]> git.lizzy.rs Git - rust.git/commitdiff
fix ice in `len_zero` lint when type has no inherent impls at all
authorOliver 'ker' Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 10 Nov 2016 16:06:39 +0000 (17:06 +0100)
committerOliver 'ker' Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 10 Nov 2016 16:06:39 +0000 (17:06 +0100)
fixes #1336

clippy_lints/src/len_zero.rs
tests/ice_exacte_size.rs [new file with mode: 0644]

index 68dff35533206a8477084846b892a24eb8d06f6e..7ca24208fdfff63ec8aec44f8725b2bcca09960f 100644 (file)
@@ -194,11 +194,11 @@ fn is_is_empty(item: &ImplOrTraitItem) -> 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 (file)
index 0000000..37e3b4e
--- /dev/null
@@ -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 { }