Skip to content

Commit

Permalink
Enable len_zero for slices
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkuu committed Feb 25, 2017
1 parent 96291e7 commit 5906639
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/len_zero.rs
Expand Up @@ -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,
}
}
2 changes: 1 addition & 1 deletion clippy_lints/src/utils/mod.rs
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/len_zero.rs
Expand Up @@ -185,3 +185,8 @@ fn main() {
println!("Or this!");
}
}

fn test_slice(b: &[u8]) {
if b.len() != 0 {
}
}
11 changes: 10 additions & 1 deletion tests/ui/len_zero.stderr
Expand Up @@ -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

0 comments on commit 5906639

Please sign in to comment.