Skip to content

Commit 5bfc256

Browse files
committed
Fix ICE in is_integer_const when the expression is inside an AnonConst body
1 parent e9c3991 commit 5bfc256

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

clippy_utils/src/lib.rs

Lines changed: 2 additions & 6 deletions
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

Lines changed: 6 additions & 0 deletions
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)