diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index f2609dd5743..cc4df4581fb 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -212,7 +212,7 @@ fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool { }, ty::TyProjection(_) => ty.ty_to_def_id().map_or(false, |id| has_is_empty_impl(cx, id)), ty::TyAdt(id, _) => has_is_empty_impl(cx, id.did), - ty::TyArray(..) | ty::TyStr => true, + ty::TyArray(..) | ty::TySlice(..) | ty::TyStr => true, _ => false, } } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index edd29cd613a..25b3ad3bfb9 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -238,7 +238,7 @@ pub fn match_path(path: &QPath, segments: &[&str]) -> bool { QPath::TypeRelative(ref ty, ref segment) => { match ty.node { TyPath(ref inner_path) => { - segments.len() > 0 && match_path(inner_path, &segments[..(segments.len() - 1)]) && + !segments.is_empty() && match_path(inner_path, &segments[..(segments.len() - 1)]) && segment.name == segments[segments.len() - 1] }, _ => false, diff --git a/tests/ui/len_zero.rs b/tests/ui/len_zero.rs index 9790f2c9fcb..d8f923bcaa9 100644 --- a/tests/ui/len_zero.rs +++ b/tests/ui/len_zero.rs @@ -185,3 +185,8 @@ fn main() { println!("Or this!"); } } + +fn test_slice(b: &[u8]) { + if b.len() != 0 { + } +} diff --git a/tests/ui/len_zero.stderr b/tests/ui/len_zero.stderr index 9ebc5209a22..e6bf6fc6306 100644 --- a/tests/ui/len_zero.stderr +++ b/tests/ui/len_zero.stderr @@ -113,5 +113,14 @@ error: length comparison to zero help: consider using `is_empty` | if with_is_empty.is_empty() { -error: aborting due to 10 previous errors +error: length comparison to zero + --> $DIR/len_zero.rs:190:8 + | +190 | if b.len() != 0 { + | ^^^^^^^^^^^^ + | +help: consider using `is_empty` + | if !b.is_empty() { + +error: aborting due to 11 previous errors