]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/needless_borrowed_ref.rs
Auto merge of #4551 - mikerite:fix-ice-reporting, r=llogiq
[rust.git] / clippy_lints / src / needless_borrowed_ref.rs
index 2c1f87c53e35596d44f3440dab069fe278ca83fe..714c746f68d6b2240e9cc921b6a2ee1ac0e0971e 100644 (file)
@@ -2,11 +2,11 @@
 //!
 //! This lint is **warn** by default
 
-use crate::utils::{in_macro, snippet, span_lint_and_then};
+use crate::utils::{snippet, span_lint_and_then};
 use if_chain::if_chain;
 use rustc::hir::{BindingAnnotation, MutImmutable, Pat, PatKind};
 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use rustc::{declare_tool_lint, lint_array};
+use rustc::{declare_lint_pass, declare_tool_lint};
 use rustc_errors::Applicability;
 
 declare_clippy_lint! {
@@ -18,7 +18,7 @@
     ///
     /// **Known problems:** It seems that the `&ref` pattern is sometimes useful.
     /// For instance in the following snippet:
-    /// ```rust
+    /// ```rust,ignore
     /// enum Animal {
     ///     Cat(u64),
     ///     Dog(u64),
@@ -26,8 +26,7 @@
     ///
     /// fn foo(a: &Animal, b: &Animal) {
     ///     match (a, b) {
-    /// (&Animal::Cat(v), k) | (k, &Animal::Cat(v)) => (), // lifetime
-    /// mismatch error
+    ///         (&Animal::Cat(v), k) | (k, &Animal::Cat(v)) => (), // lifetime mismatch error
     ///         (&Animal::Dog(ref c), &Animal::Dog(_)) => ()
     ///     }
     /// }
     "taking a needless borrowed reference"
 }
 
-#[derive(Copy, Clone)]
-pub struct NeedlessBorrowedRef;
-
-impl LintPass for NeedlessBorrowedRef {
-    fn get_lints(&self) -> LintArray {
-        lint_array!(NEEDLESS_BORROWED_REFERENCE)
-    }
-
-    fn name(&self) -> &'static str {
-        "NeedlessBorrowedRef"
-    }
-}
+declare_lint_pass!(NeedlessBorrowedRef => [NEEDLESS_BORROWED_REFERENCE]);
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef {
     fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
-        if in_macro(pat.span) {
+        if pat.span.from_expansion() {
             // OK, simple enough, lints doesn't check in macro.
             return;
         }