From d3e88a58b9fad8c68e19c7603ec2725ee26bac29 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Wed, 6 Nov 2019 18:14:47 +0100 Subject: [PATCH 1/2] Fix ICE #4775 --- clippy_lints/src/loops.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 731dd92c82a..805e609cea6 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1993,7 +1993,13 @@ fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr) -> bool { fn is_iterable_array<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'_, 'tcx>) -> bool { // IntoIterator is currently only implemented for array sizes <= 32 in rustc match ty.kind { - ty::Array(_, n) => (0..=32).contains(&n.eval_usize(cx.tcx, cx.param_env)), + ty::Array(_, n) => { + if let Some(val) = n.try_eval_usize(cx.tcx, cx.param_env) { + (0..=32).contains(&val) + } else { + false + } + }, _ => false, } } From 073dbd42182febdf35f5193e891c4e24722dbca9 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Wed, 6 Nov 2019 18:15:04 +0100 Subject: [PATCH 2/2] Add regression test for ICE #4775 --- tests/ui/ice-4775.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/ui/ice-4775.rs diff --git a/tests/ui/ice-4775.rs b/tests/ui/ice-4775.rs new file mode 100644 index 00000000000..31e53e846d5 --- /dev/null +++ b/tests/ui/ice-4775.rs @@ -0,0 +1,14 @@ +#![feature(const_generics)] +#![allow(incomplete_features)] + +pub struct ArrayWrapper([usize; N]); + +impl ArrayWrapper<{ N }> { + pub fn ice(&self) { + for i in self.0.iter() { + println!("{}", i); + } + } +} + +fn main() {}