Skip to content

Commit e93df0b

Browse files
committed
Auto merge of #7473 - Jarcho:ice_7340, r=Manishearth
Fix ICE in `is_integer_const` fixes: #7340 changelog: Fix ICE in `modulo_one` in const contexts
2 parents e9c3991 + 5bfc256 commit e93df0b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

clippy_utils/src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -909,12 +909,8 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool
909909
if is_integer_literal(e, value) {
910910
return true;
911911
}
912-
let map = cx.tcx.hir();
913-
let parent_item = map.get_parent_item(e.hir_id);
914-
if let Some((Constant::Int(v), _)) = map
915-
.maybe_body_owned_by(parent_item)
916-
.and_then(|body_id| constant(cx, cx.tcx.typeck_body(body_id), e))
917-
{
912+
let enclosing_body = cx.tcx.hir().local_def_id(cx.tcx.hir().enclosing_body_owner(e.hir_id));
913+
if let Some((Constant::Int(v), _)) = constant(cx, cx.tcx.typeck(enclosing_body), e) {
918914
value == v
919915
} else {
920916
false

tests/ui/crashes/ice-7340.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![allow(clippy::no_effect)]
2+
3+
fn main() {
4+
const CONSTANT: usize = 8;
5+
[1; 1 % CONSTANT];
6+
}

0 commit comments

Comments
 (0)