Skip to content

Commit 3edf712

Browse files
authored
Merge pull request #1337 from oli-obk/master
fix ice in `len_zero` lint when type has no inherent impls at all
2 parents 2cfe1e7 + cfae1e9 commit 3edf712

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clippy_lints/src/len_zero.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool {
194194

195195
/// Check the inherent impl's items for an `is_empty(self)` method.
196196
fn has_is_empty_impl(cx: &LateContext, id: DefId) -> bool {
197-
cx.tcx.inherent_impls.borrow()[&id].iter().any(|imp| {
197+
cx.tcx.inherent_impls.borrow().get(&id).map_or(false, |impls| impls.iter().any(|imp| {
198198
cx.tcx.impl_or_trait_items(*imp).iter().any(|item| {
199199
is_is_empty(&cx.tcx.impl_or_trait_item(*item))
200200
})
201-
})
201+
}))
202202
}
203203

204204
let ty = &walk_ptrs_ty(cx.tcx.expr_ty(expr));

tests/ice_exacte_size.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(plugin)]
2+
#![plugin(clippy)]
3+
#![deny(clippy)]
4+
5+
#[allow(dead_code)]
6+
struct Foo;
7+
8+
impl Iterator for Foo {
9+
type Item = ();
10+
11+
fn next(&mut self) -> Option<()> {
12+
let _ = self.len() == 0;
13+
unimplemented!()
14+
}
15+
}
16+
17+
impl ExactSizeIterator for Foo { }

0 commit comments

Comments
 (0)