]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/booleans.rs
Auto merge of #4809 - iankronquist:patch-1, r=flip1995
[rust.git] / clippy_lints / src / booleans.rs
index 4029d5cabfe6c8d21e5cfd2ae684208df559c44b..60e62542a7255b5499e497fe06752fa08b8ae656 100644 (file)
@@ -3,12 +3,13 @@
     span_lint_and_then, SpanlessEq,
 };
 use if_chain::if_chain;
-use rustc::declare_lint_pass;
-use rustc::hir::intravisit::*;
-use rustc::hir::*;
-use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
+use rustc::hir::map::Map;
 use rustc_errors::Applicability;
-use rustc_session::declare_tool_lint;
+use rustc_hir::intravisit;
+use rustc_hir::intravisit::*;
+use rustc_hir::*;
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
 use rustc_span::source_map::Span;
 use syntax::ast::LitKind;
 
@@ -109,7 +110,7 @@ fn negate(bin_op_kind: BinOpKind) -> Option<BinOpKind> {
         // prevent folding of `cfg!` macros and the like
         if !e.span.from_expansion() {
             match &e.kind {
-                ExprKind::Unary(UnNot, inner) => return Ok(Bool::Not(box self.run(inner)?)),
+                ExprKind::Unary(UnOp::UnNot, inner) => return Ok(Bool::Not(box self.run(inner)?)),
                 ExprKind::Binary(binop, lhs, rhs) => match &binop.node {
                     BinOpKind::Or => return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?)),
                     BinOpKind::And => return Ok(Bool::And(self.extract(BinOpKind::And, &[lhs, rhs], Vec::new())?)),
@@ -206,7 +207,7 @@ fn recurse(&mut self, suggestion: &Bool) -> Option<()> {
                 }
             },
             Or(v) => {
-                for (index, inner) in v.iter().enumerate() {
+                for (index, inner) in v.iter().rev().enumerate() {
                     if index > 0 {
                         self.output.push_str(" || ");
                     }
@@ -437,6 +438,8 @@ fn bool_expr(&self, e: &'tcx Expr<'_>) {
 }
 
 impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
+    type Map = Map<'tcx>;
+
     fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
         if in_macro(e.span) {
             return;
@@ -445,7 +448,7 @@ fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
             ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => {
                 self.bool_expr(e)
             },
-            ExprKind::Unary(UnNot, inner) => {
+            ExprKind::Unary(UnOp::UnNot, inner) => {
                 if self.cx.tables.node_types()[inner.hir_id].is_bool() {
                     self.bool_expr(e);
                 } else {
@@ -455,7 +458,7 @@ fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
             _ => walk_expr(self, e),
         }
     }
-    fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
+    fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
         NestedVisitorMap::None
     }
 }
@@ -470,8 +473,10 @@ struct NotSimplificationVisitor<'a, 'tcx> {
 }
 
 impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
+    type Map = Map<'tcx>;
+
     fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
-        if let ExprKind::Unary(UnNot, inner) = &expr.kind {
+        if let ExprKind::Unary(UnOp::UnNot, inner) = &expr.kind {
             if let Some(suggestion) = simplify_not(self.cx, inner) {
                 span_lint_and_sugg(
                     self.cx,
@@ -487,7 +492,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
 
         walk_expr(self, expr);
     }
-    fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
+    fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
         NestedVisitorMap::None
     }
 }