Enable len_zero for slices

This commit is contained in:
sinkuu 2017-02-25 12:26:33 +09:00
parent 96291e7d1c
commit 5906639af5
4 changed files with 17 additions and 3 deletions

View File

@ -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,
}
}

View File

@ -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,

View File

@ -185,3 +185,8 @@ fn main() {
println!("Or this!");
}
}
fn test_slice(b: &[u8]) {
if b.len() != 0 {
}
}

View File

@ -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