Skip to content

Commit

Permalink
Auto merge of #4780 - flip1995:ice_4775, r=phansch
Browse files Browse the repository at this point in the history
Fix ICE #4775

Fixes #4775

changelog: Fix ICE with const_generics
  • Loading branch information
bors committed Nov 11, 2019
2 parents 3abdd2f + 073dbd4 commit 338f5e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/ice-4775.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![feature(const_generics)]
#![allow(incomplete_features)]

pub struct ArrayWrapper<const N: usize>([usize; N]);

impl<const N: usize> ArrayWrapper<{ N }> {
pub fn ice(&self) {
for i in self.0.iter() {
println!("{}", i);
}
}
}

fn main() {}

0 comments on commit 338f5e6

Please sign in to comment.