diff --git a/src/len_zero.rs b/src/len_zero.rs index 548a3d92c2c..e61c77adf24 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/src/panic.rs b/src/panic.rs index 60a3ce1a461..7dbcf2a5b30 100644 --- a/src/panic.rs +++ b/src/panic.rs @@ -37,7 +37,8 @@ impl LateLintPass for PanicPass { match_path(path, &BEGIN_UNWIND), let ExprLit(ref lit) = params[0].node, let LitKind::Str(ref string, _) = lit.node, - string.contains('{'), + let Some(par) = string.find('{'), + string[par..].contains('}'), let Some(sp) = cx.sess().codemap() .with_expn_info(expr.span.expn_id, |info| info.map(|i| i.call_site)) diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 625e8da197d..ee2e2d7206f 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -383,14 +383,14 @@ fn trim_multiline_inner(s: Cow, ignore_first: bool, ch: char) -> Cow { let x = s.lines() .skip(ignore_first as usize) .filter_map(|l| { - if l.len() > 0 { + if l.is_empty() { + None + } else { // ignore empty lines Some(l.char_indices() .find(|&(_, x)| x != ch) .unwrap_or((l.len(), ch)) .0) - } else { - None } }) .min() @@ -399,7 +399,7 @@ fn trim_multiline_inner(s: Cow, ignore_first: bool, ch: char) -> Cow { Cow::Owned(s.lines() .enumerate() .map(|(i, l)| { - if (ignore_first && i == 0) || l.len() == 0 { + if (ignore_first && i == 0) || l.is_empty() { l } else { l.split_at(x).1 diff --git a/tests/compile-fail/len_zero.rs b/tests/compile-fail/len_zero.rs index 9814a1c2d7d..5168f80b856 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!"); diff --git a/tests/compile-fail/panic.rs b/tests/compile-fail/panic.rs index 36427f4330b..38fe5aa2c0f 100644 --- a/tests/compile-fail/panic.rs +++ b/tests/compile-fail/panic.rs @@ -4,10 +4,14 @@ #[deny(panic_params)] fn missing() { - panic!("{}"); //~ERROR: You probably are missing some parameter + if true { + panic!("{}"); //~ERROR: You probably are missing some parameter + } else { + panic!("{:?}"); //~ERROR: You probably are missing some parameter + } } -fn ok_sigle() { +fn ok_single() { panic!("foo bar"); } @@ -15,8 +19,18 @@ fn ok_multiple() { panic!("{}", "This is {ok}"); } +fn ok_bracket() { + // the match is just here because of #759, it serves no other purpose for the lint + match 42 { + 1337 => panic!("{so is this"), + 666 => panic!("so is this}"), + _ => panic!("}so is that{"), + } +} + fn main() { missing(); - ok_sigle(); + ok_single(); ok_multiple(); + ok_bracket(); }