Skip to content

Commit cfae1e9

Browse files
committed
fix ice in len_zero lint when type has no inherent impls at all
fixes #1336
1 parent 2cfe1e7 commit cfae1e9

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clippy_lints/src/len_zero.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 17 additions & 0 deletions
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)