Merge pull request #1573 from sinkuu/len_zero_slice

Enable `len_zero` for slices
This commit is contained in:
llogiq 2017-02-25 07:29:58 +01:00 committed by GitHub
commit 455fa0c40a
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