diff --git a/src/needless_bool.rs b/src/needless_bool.rs index a40b4b3a252..5382b8f0f04 100644 --- a/src/needless_bool.rs +++ b/src/needless_bool.rs @@ -107,47 +107,43 @@ impl LateLintPass for BoolComparison { if let ExprBinary(Spanned{ node: BiEq, .. }, ref left_side, ref right_side) = e.node { match (fetch_bool_expr(left_side), fetch_bool_expr(right_side)) { (Some(true), None) => { - let side_snip = snippet(cx, right_side.span, ".."); - let hint = format!("`{}`", side_snip); + let hint = format!("{}", snippet(cx, right_side.span, "..")); span_lint_and_then(cx, BOOL_COMPARISON, e.span, - "equality checks against booleans are unnecesary", + "equality checks against true are unnecesary", |db| { - db.span_suggestion(e.span, "try simplifying it:", hint); + db.span_suggestion(e.span, "try simplifying it as shown:", hint); }); } (None, Some(true)) => { - let side_snip = snippet(cx, left_side.span, ".."); - let hint = format!("`{}`", side_snip); + let hint = format!("{}", snippet(cx, left_side.span, "..")); span_lint_and_then(cx, BOOL_COMPARISON, e.span, - "equality checks against booleans are unnecesary", + "equality checks against true are unnecesary", |db| { - db.span_suggestion(e.span, "try simplifying it:", hint); + db.span_suggestion(e.span, "try simplifying it as shown:", hint); }); } (Some(false), None) => { - let side_snip = snippet(cx, right_side.span, ".."); - let hint = format!("`!{}`", side_snip); + let hint = format!("!{}", snippet(cx, right_side.span, "..")); span_lint_and_then(cx, BOOL_COMPARISON, e.span, - "equality checks against booleans are unnecesary", + "equality checks against false can be replaced by a negation", |db| { - db.span_suggestion(e.span, "try simplifying it:", hint); + db.span_suggestion(e.span, "try simplifying it as shown:", hint); }); } (None, Some(false)) => { - let side_snip = snippet(cx, left_side.span, ".."); - let hint = format!("`!{}`", side_snip); + let hint = format!("!{}", snippet(cx, left_side.span, "..")); span_lint_and_then(cx, BOOL_COMPARISON, e.span, - "equality checks against booleans are unnecesary", + "equality checks against false can be replaced by a negation", |db| { - db.span_suggestion(e.span, "try simplifying it:", hint); + db.span_suggestion(e.span, "try simplifying it as shown:", hint); }); } _ => (), diff --git a/tests/compile-fail/bool_comparison.rs b/tests/compile-fail/bool_comparison.rs index 468b8382e94..8a792931d02 100644 --- a/tests/compile-fail/bool_comparison.rs +++ b/tests/compile-fail/bool_comparison.rs @@ -5,19 +5,19 @@ fn main() { let x = true; if x == true { "yes" } else { "no" }; - //~^ ERROR equality checks against booleans are unnecesary - //~| HELP try simplifying it: - //~| SUGGESTION x + //~^ ERROR equality checks against true are unnecesary + //~| HELP try simplifying it as shown: + //~| SUGGESTION if x { "yes" } else { "no" }; if x == false { "yes" } else { "no" }; - //~^ ERROR equality checks against booleans are unnecesary - //~| HELP try simplifying it: - //~| SUGGESTION !x + //~^ ERROR equality checks against false can be replaced by a negation + //~| HELP try simplifying it as shown: + //~| SUGGESTION if !x { "yes" } else { "no" }; if true == x { "yes" } else { "no" }; - //~^ ERROR equality checks against booleans are unnecesary - //~| HELP try simplifying it: - //~| SUGGESTION x + //~^ ERROR equality checks against true are unnecesary + //~| HELP try simplifying it as shown: + //~| SUGGESTION if x { "yes" } else { "no" }; if false == x { "yes" } else { "no" }; - //~^ ERROR equality checks against booleans are unnecesary - //~| HELP try simplifying it: - //~| SUGGESTION !x + //~^ ERROR equality checks against false can be replaced by a negation + //~| HELP try simplifying it as shown: + //~| SUGGESTION if !x { "yes" } else { "no" }; }