Skip to content

Commit 338f5e6

Browse files
committed
Auto merge of #4780 - flip1995:ice_4775, r=phansch
Fix ICE #4775 Fixes #4775 changelog: Fix ICE with const_generics
2 parents 3abdd2f + 073dbd4 commit 338f5e6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clippy_lints/src/loops.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,13 @@ fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr) -> bool {
19931993
fn is_iterable_array<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'_, 'tcx>) -> bool {
19941994
// IntoIterator is currently only implemented for array sizes <= 32 in rustc
19951995
match ty.kind {
1996-
ty::Array(_, n) => (0..=32).contains(&n.eval_usize(cx.tcx, cx.param_env)),
1996+
ty::Array(_, n) => {
1997+
if let Some(val) = n.try_eval_usize(cx.tcx, cx.param_env) {
1998+
(0..=32).contains(&val)
1999+
} else {
2000+
false
2001+
}
2002+
},
19972003
_ => false,
19982004
}
19992005
}

tests/ui/ice-4775.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(const_generics)]
2+
#![allow(incomplete_features)]
3+
4+
pub struct ArrayWrapper<const N: usize>([usize; N]);
5+
6+
impl<const N: usize> ArrayWrapper<{ N }> {
7+
pub fn ice(&self) {
8+
for i in self.0.iter() {
9+
println!("{}", i);
10+
}
11+
}
12+
}
13+
14+
fn main() {}

0 commit comments

Comments
 (0)