Skip to content

Commit

Permalink
Fix ICE in is_integer_const when the expression is inside an `AnonC…
Browse files Browse the repository at this point in the history
…onst` body
  • Loading branch information
Jarcho committed Jul 17, 2021
1 parent e9c3991 commit 5bfc256
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 2 additions & 6 deletions clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,12 +909,8 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool
if is_integer_literal(e, value) {
return true;
}
let map = cx.tcx.hir();
let parent_item = map.get_parent_item(e.hir_id);
if let Some((Constant::Int(v), _)) = map
.maybe_body_owned_by(parent_item)
.and_then(|body_id| constant(cx, cx.tcx.typeck_body(body_id), e))
{
let enclosing_body = cx.tcx.hir().local_def_id(cx.tcx.hir().enclosing_body_owner(e.hir_id));
if let Some((Constant::Int(v), _)) = constant(cx, cx.tcx.typeck(enclosing_body), e) {
value == v
} else {
false
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/crashes/ice-7340.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![allow(clippy::no_effect)]

fn main() {
const CONSTANT: usize = 8;
[1; 1 % CONSTANT];
}

0 comments on commit 5bfc256

Please sign in to comment.