diff options
| author | bors <bors@rust-lang.org> | 2021-07-18 03:32:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-18 03:32:31 +0000 |
| commit | e93df0bef973fc1bb10edf00595bd17a55712f23 (patch) | |
| tree | 54ef496a6bc2045fe594296eb7b3890b5026ab27 | |
| parent | e9c3991d3081c79bd712d754e6f51f456e603c6c (diff) | |
| parent | 5bfc2568a21148c5c2dd9455e1720e4fc9021ed2 (diff) | |
| download | rust-e93df0bef973fc1bb10edf00595bd17a55712f23.tar.gz rust-e93df0bef973fc1bb10edf00595bd17a55712f23.zip | |
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
| -rw-r--r-- | clippy_utils/src/lib.rs | 8 | ||||
| -rw-r--r-- | tests/ui/crashes/ice-7340.rs | 6 |
2 files changed, 8 insertions, 6 deletions
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 6db221ab0fd..9a9d6a20057 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -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 diff --git a/tests/ui/crashes/ice-7340.rs b/tests/ui/crashes/ice-7340.rs new file mode 100644 index 00000000000..7d2351d606f --- /dev/null +++ b/tests/ui/crashes/ice-7340.rs @@ -0,0 +1,6 @@ +#![allow(clippy::no_effect)] + +fn main() { + const CONSTANT: usize = 8; + [1; 1 % CONSTANT]; +} |
