Skip to content

Commit 7eef989

Browse files
committed
Add str to types considered by len_zero
1 parent 04d8179 commit 7eef989

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/len_zero.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool {
198198
}
199199
ty::TyProjection(_) => ty.ty_to_def_id().map_or(false, |id| has_is_empty_impl(cx, &id)),
200200
ty::TyEnum(ref id, _) | ty::TyStruct(ref id, _) => has_is_empty_impl(cx, &id.did),
201-
ty::TyArray(..) => true,
201+
ty::TyArray(..) | ty::TyStr => true,
202202
_ => false,
203203
}
204204
}

tests/compile-fail/len_zero.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ fn main() {
7676
println!("This should not happen!");
7777
}
7878

79+
if "".len() == 0 {
80+
//~^ERROR length comparison to zero
81+
//~|HELP consider using `is_empty`
82+
//~|SUGGESTION "".is_empty()
83+
}
84+
7985
let y = One;
8086
if y.len() == 0 { //no error because One does not have .is_empty()
8187
println!("This should not happen either!");

0 commit comments

Comments
 (0)