From 7eef989ff4859f9b551b3905f2bf30c6ff113872 Mon Sep 17 00:00:00 2001 From: mcarton Date: Sat, 12 Mar 2016 21:12:35 +0100 Subject: [PATCH] Add `str` to types considered by `len_zero` --- src/len_zero.rs | 2 +- tests/compile-fail/len_zero.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/len_zero.rs b/src/len_zero.rs index 548a3d92c..e61c77adf 100644 --- a/src/len_zero.rs +++ b/src/len_zero.rs @@ -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, } } diff --git a/tests/compile-fail/len_zero.rs b/tests/compile-fail/len_zero.rs index 9814a1c2d..5168f80b8 100644 --- a/tests/compile-fail/len_zero.rs +++ b/tests/compile-fail/len_zero.rs @@ -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!");