Add str to types considered by len_zero

This commit is contained in:
mcarton 2016-03-12 21:12:35 +01:00
parent 04d81799a2
commit 7eef989ff4
2 changed files with 7 additions and 1 deletions

View file

@ -198,7 +198,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::TyEnum(ref id, _) | ty::TyStruct(ref id, _) => has_is_empty_impl(cx, &id.did),
ty::TyArray(..) => true,
ty::TyArray(..) | ty::TyStr => true,
_ => false,
}
}

View file

@ -76,6 +76,12 @@ fn main() {
println!("This should not happen!");
}
if "".len() == 0 {
//~^ERROR length comparison to zero
//~|HELP consider using `is_empty`
//~|SUGGESTION "".is_empty()
}
let y = One;
if y.len() == 0 { //no error because One does not have .is_empty()
println!("This should not happen either!");