Skip to content

fix ice in len_zero lint when type has no inherent impls at all #1337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clippy_lints/src/len_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
17 changes: 17 additions & 0 deletions tests/ice_exacte_size.rs
Original file line number Diff line number Diff line change
@@ -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 { }