From cfae1e9fda47587aa87ed7c1123001b7897315b4 Mon Sep 17 00:00:00 2001 From: Oliver 'ker' Schneider Date: Thu, 10 Nov 2016 17:06:39 +0100 Subject: [PATCH] fix ice in `len_zero` lint when type has no inherent impls at all fixes #1336 --- clippy_lints/src/len_zero.rs | 4 ++-- tests/ice_exacte_size.rs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/ice_exacte_size.rs diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 68dff3553320..7ca24208fdff 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -194,11 +194,11 @@ fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool { /// Check the inherent impl's items for an `is_empty(self)` method. fn has_is_empty_impl(cx: &LateContext, id: DefId) -> bool { - cx.tcx.inherent_impls.borrow()[&id].iter().any(|imp| { + cx.tcx.inherent_impls.borrow().get(&id).map_or(false, |impls| impls.iter().any(|imp| { cx.tcx.impl_or_trait_items(*imp).iter().any(|item| { is_is_empty(&cx.tcx.impl_or_trait_item(*item)) }) - }) + })) } let ty = &walk_ptrs_ty(cx.tcx.expr_ty(expr)); diff --git a/tests/ice_exacte_size.rs b/tests/ice_exacte_size.rs new file mode 100644 index 000000000000..37e3b4ebe7a9 --- /dev/null +++ b/tests/ice_exacte_size.rs @@ -0,0 +1,17 @@ +#![feature(plugin)] +#![plugin(clippy)] +#![deny(clippy)] + +#[allow(dead_code)] +struct Foo; + +impl Iterator for Foo { + type Item = (); + + fn next(&mut self) -> Option<()> { + let _ = self.len() == 0; + unimplemented!() + } +} + +impl ExactSizeIterator for Foo { }