]> git.lizzy.rs Git - rust.git/commitdiff
Merge branch 'pr-645'
authorManish Goregaokar <manishsmail@gmail.com>
Wed, 10 Feb 2016 04:50:23 +0000 (10:20 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Wed, 10 Feb 2016 04:50:23 +0000 (10:20 +0530)
1  2 
README.md
src/lib.rs
src/needless_bool.rs

diff --cc README.md
Simple merge
diff --cc src/lib.rs
Simple merge
index bfd819edcb6743f954d0b9c8a383a16ad3e04249,5382b8f0f0401a743578ee9737bf6e874072800d..4ddd8f2f3c5db13b32f97fb9c9d0b3cf54cf994b
@@@ -78,6 -93,65 +93,65 @@@ impl LateLintPass for NeedlessBool 
      }
  }
  
 -                    let hint = format!("{}", snippet(cx, right_side.span, ".."));
+ #[derive(Copy,Clone)]
+ pub struct BoolComparison;
+ impl LintPass for BoolComparison {
+     fn get_lints(&self) -> LintArray {
+         lint_array!(BOOL_COMPARISON)
+     }
+ }
+ impl LateLintPass for BoolComparison {
+     fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
+         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 hint = format!("{}", snippet(cx, left_side.span, ".."));
++                    let hint = snippet(cx, right_side.span, "..").into_owned();
+                     span_lint_and_then(cx,
+                                        BOOL_COMPARISON,
+                                        e.span,
+                                        "equality checks against true are unnecesary",
+                                        |db| {
+                                            db.span_suggestion(e.span, "try simplifying it as shown:", hint);
+                                        });
+                 }
+                 (None, Some(true)) => {
++                    let hint = snippet(cx, left_side.span, "..").into_owned();
+                     span_lint_and_then(cx,
+                                        BOOL_COMPARISON,
+                                        e.span,
+                                        "equality checks against true are unnecesary",
+                                        |db| {
+                                            db.span_suggestion(e.span, "try simplifying it as shown:", hint);
+                                        });
+                 }
+                 (Some(false), None) => {
+                     let hint = format!("!{}", snippet(cx, right_side.span, ".."));
+                     span_lint_and_then(cx,
+                                        BOOL_COMPARISON,
+                                        e.span,
+                                        "equality checks against false can be replaced by a negation",
+                                        |db| {
+                                            db.span_suggestion(e.span, "try simplifying it as shown:", hint);
+                                        });
+                 }
+                 (None, Some(false)) => {
+                     let hint = format!("!{}", snippet(cx, left_side.span, ".."));
+                     span_lint_and_then(cx,
+                                        BOOL_COMPARISON,
+                                        e.span,
+                                        "equality checks against false can be replaced by a negation",
+                                        |db| {
+                                            db.span_suggestion(e.span, "try simplifying it as shown:", hint);
+                                        });
+                 }
+                 _ => (),
+             }
+         }
+     }
+ }
  fn fetch_bool_block(block: &Block) -> Option<bool> {
      if block.stmts.is_empty() {
          block.expr.as_ref().and_then(|e| fetch_bool_expr(e))