//!
//! 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! {
///
/// **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),
///
/// 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;
}