about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Wright <mikerite@lavabit.com>2019-06-21 08:14:07 +0200
committerMichael Wright <mikerite@lavabit.com>2019-06-21 08:14:07 +0200
commit837b5208f78bada92bcd017e4b3763ba791193e5 (patch)
tree8aa5a202ed39443b57460adfa5822d022a894ebc
parent7db5d0e6de112440dd13e78e2cc0bb1a7be25641 (diff)
downloadrust-837b5208f78bada92bcd017e4b3763ba791193e5.tar.gz
rust-837b5208f78bada92bcd017e4b3763ba791193e5.zip
Fix breakage due to rust-lang/rust#61968
-rw-r--r--clippy_lints/src/booleans.rs53
-rw-r--r--clippy_lints/src/double_comparison.rs2
-rw-r--r--clippy_lints/src/inherent_impl.rs13
-rw-r--r--clippy_lints/src/question_mark.rs6
-rw-r--r--clippy_lints/src/utils/mod.rs4
5 files changed, 37 insertions, 41 deletions
diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs
index 0acf620cd17..caf418c9b5b 100644
--- a/clippy_lints/src/booleans.rs
+++ b/clippy_lints/src/booleans.rs
@@ -2,14 +2,14 @@ use crate::utils::{
     get_trait_def_id, implements_trait, in_macro, in_macro_or_desugar, match_type, paths, snippet_opt,
     span_lint_and_then, SpanlessEq,
 };
+use if_chain::if_chain;
 use rustc::hir::intravisit::*;
 use rustc::hir::*;
 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
 use rustc::{declare_lint_pass, declare_tool_lint};
-use rustc_data_structures::thin_vec::ThinVec;
 use rustc_errors::Applicability;
 use syntax::ast::LitKind;
-use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
+use syntax::source_map::Span;
 
 declare_clippy_lint! {
     /// **What it does:** Checks for boolean expressions that can be written more
@@ -93,6 +93,18 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
     }
 
     fn run(&mut self, e: &'v Expr) -> Result<Bool, String> {
+        fn negate(bin_op_kind: BinOpKind) -> Option<BinOpKind> {
+            match bin_op_kind {
+                BinOpKind::Eq => Some(BinOpKind::Ne),
+                BinOpKind::Ne => Some(BinOpKind::Eq),
+                BinOpKind::Gt => Some(BinOpKind::Le),
+                BinOpKind::Ge => Some(BinOpKind::Lt),
+                BinOpKind::Lt => Some(BinOpKind::Ge),
+                BinOpKind::Le => Some(BinOpKind::Gt),
+                _ => None,
+            }
+        }
+
         // prevent folding of `cfg!` macros and the like
         if !in_macro_or_desugar(e.span) {
             match &e.node {
@@ -115,33 +127,18 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
                 #[allow(clippy::cast_possible_truncation)]
                 return Ok(Bool::Term(n as u8));
             }
-            let negated = match &e.node {
-                ExprKind::Binary(binop, lhs, rhs) => {
-                    if !implements_ord(self.cx, lhs) {
-                        continue;
-                    }
 
-                    let mk_expr = |op| Expr {
-                        hir_id: DUMMY_HIR_ID,
-                        span: DUMMY_SP,
-                        attrs: ThinVec::new(),
-                        node: ExprKind::Binary(dummy_spanned(op), lhs.clone(), rhs.clone()),
-                    };
-                    match binop.node {
-                        BinOpKind::Eq => mk_expr(BinOpKind::Ne),
-                        BinOpKind::Ne => mk_expr(BinOpKind::Eq),
-                        BinOpKind::Gt => mk_expr(BinOpKind::Le),
-                        BinOpKind::Ge => mk_expr(BinOpKind::Lt),
-                        BinOpKind::Lt => mk_expr(BinOpKind::Ge),
-                        BinOpKind::Le => mk_expr(BinOpKind::Gt),
-                        _ => continue,
-                    }
-                },
-                _ => continue,
-            };
-            if SpanlessEq::new(self.cx).ignore_fn().eq_expr(&negated, expr) {
-                #[allow(clippy::cast_possible_truncation)]
-                return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));
+            if_chain! {
+                if let ExprKind::Binary(e_binop, e_lhs, e_rhs) = &e.node;
+                if implements_ord(self.cx, e_lhs);
+                if let ExprKind::Binary(expr_binop, expr_lhs, expr_rhs) = &expr.node;
+                if negate(e_binop.node) == Some(expr_binop.node);
+                if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_lhs, expr_lhs);
+                if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_rhs, expr_rhs);
+                then {
+                    #[allow(clippy::cast_possible_truncation)]
+                    return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));
+                }
             }
         }
         let n = self.terminals.len();
diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs
index 0f5a88d3dde..228d53ff113 100644
--- a/clippy_lints/src/double_comparison.rs
+++ b/clippy_lints/src/double_comparison.rs
@@ -36,7 +36,7 @@ declare_lint_pass!(DoubleComparisons => [DOUBLE_COMPARISONS]);
 impl<'a, 'tcx> DoubleComparisons {
     #[allow(clippy::similar_names)]
     fn check_binop(self, cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr, rhs: &'tcx Expr, span: Span) {
-        let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (lhs.node.clone(), rhs.node.clone()) {
+        let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (&lhs.node, &rhs.node) {
             (ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => {
                 (lb.node, llhs, lrhs, rb.node, rlhs, rrhs)
             },
diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs
index bde784f81de..27170817def 100644
--- a/clippy_lints/src/inherent_impl.rs
+++ b/clippy_lints/src/inherent_impl.rs
@@ -42,7 +42,7 @@ declare_clippy_lint! {
 #[allow(clippy::module_name_repetitions)]
 #[derive(Default)]
 pub struct MultipleInherentImpl {
-    impls: FxHashMap<def_id::DefId, (Span, Generics)>,
+    impls: FxHashMap<def_id::DefId, Span>,
 }
 
 impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]);
@@ -51,8 +51,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl {
     fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) {
         if let ItemKind::Impl(_, _, _, ref generics, None, _, _) = item.node {
             // Remember for each inherent implementation encoutered its span and generics
-            self.impls
-                .insert(item.hir_id.owner_def_id(), (item.span, generics.clone()));
+            // but filter out implementations that have generic params (type or lifetime)
+            if generics.params.len() == 0 {
+                self.impls.insert(item.hir_id.owner_def_id(), item.span);
+            }
         }
     }
 
@@ -66,10 +68,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl {
                 .values()
             {
                 // Filter out implementations that have generic params (type or lifetime)
-                let mut impl_spans = impls
-                    .iter()
-                    .filter_map(|impl_def| self.impls.get(impl_def))
-                    .filter_map(|(span, generics)| if generics.params.len() == 0 { Some(span) } else { None });
+                let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def));
                 if let Some(initial_span) = impl_spans.nth(0) {
                     impl_spans.for_each(|additional_span| {
                         span_lint_and_then(
diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs
index da038800c2d..9e0f7d0f3c2 100644
--- a/clippy_lints/src/question_mark.rs
+++ b/clippy_lints/src/question_mark.rs
@@ -129,7 +129,7 @@ impl QuestionMark {
         }
     }
 
-    fn return_expression(block: &Block) -> Option<P<Expr>> {
+    fn return_expression(block: &Block) -> Option<&P<Expr>> {
         // Check if last expression is a return statement. Then, return the expression
         if_chain! {
             if block.stmts.len() == 1;
@@ -139,7 +139,7 @@ impl QuestionMark {
             if let &Some(ref ret_expr) = ret_expr;
 
             then {
-                return Some(ret_expr.clone());
+                return Some(ret_expr);
             }
         }
 
@@ -148,7 +148,7 @@ impl QuestionMark {
             if block.stmts.len() == 0;
             if let Some(ExprKind::Ret(Some(ret_expr))) = block.expr.as_ref().map(|e| &e.node);
             then {
-                return Some(ret_expr.clone());
+                return Some(ret_expr);
             }
         }
 
diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs
index bee44d092ee..b7bc4900c5d 100644
--- a/clippy_lints/src/utils/mod.rs
+++ b/clippy_lints/src/utils/mod.rs
@@ -315,14 +315,14 @@ pub fn implements_trait<'a, 'tcx>(
 ///     }
 /// }
 /// ```
-pub fn trait_ref_of_method(cx: &LateContext<'_, '_>, hir_id: HirId) -> Option<TraitRef> {
+pub fn trait_ref_of_method<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, hir_id: HirId) -> Option<&'a TraitRef> {
     // Get the implemented trait for the current function
     let parent_impl = cx.tcx.hir().get_parent_item(hir_id);
     if_chain! {
         if parent_impl != hir::CRATE_HIR_ID;
         if let hir::Node::Item(item) = cx.tcx.hir().get_by_hir_id(parent_impl);
         if let hir::ItemKind::Impl(_, _, _, _, trait_ref, _, _) = &item.node;
-        then { return trait_ref.clone(); }
+        then { return trait_ref.as_ref(); }
     }
     None
 }