]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/equatable_if_let.rs
Shrink `Token`.
[rust.git] / clippy_lints / src / equatable_if_let.rs
index 06d128f5527b5d8ba3d965b65853c1a0507cf153..fdfb821ac7895becb9fa97f56463dad42f0b7632 100644 (file)
@@ -4,7 +4,8 @@
 use if_chain::if_chain;
 use rustc_errors::Applicability;
 use rustc_hir::{Expr, ExprKind, Pat, PatKind};
-use rustc_lint::{LateContext, LateLintPass};
+use rustc_lint::{LateContext, LateLintPass, LintContext};
+use rustc_middle::lint::in_external_macro;
 use rustc_middle::ty::Ty;
 use rustc_session::{declare_lint_pass, declare_tool_lint};
 
@@ -26,7 +27,7 @@
     ///     do_thing();
     /// }
     /// ```
-    /// Should be written
+    /// Use instead:
     /// ```rust,ignore
     /// if x == Some(2) {
     ///     do_thing();
@@ -56,7 +57,7 @@ fn array_rec(pats: &[Pat<'_>]) -> bool {
     }
 }
 
-fn is_structural_partial_eq(cx: &LateContext<'tcx>, ty: Ty<'tcx>, other: Ty<'tcx>) -> bool {
+fn is_structural_partial_eq<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, other: Ty<'tcx>) -> bool {
     if let Some(def_id) = cx.tcx.lang_items().eq_trait() {
         implements_trait(cx, ty, def_id, &[other.into()])
     } else {
@@ -67,6 +68,7 @@ fn is_structural_partial_eq(cx: &LateContext<'tcx>, ty: Ty<'tcx>, other: Ty<'tcx
 impl<'tcx> LateLintPass<'tcx> for PatternEquality {
     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
         if_chain! {
+            if !in_external_macro(cx.sess(), expr.span);
             if let ExprKind::Let(let_expr) = expr.kind;
             if unary_pattern(let_expr.pat);
             let exp_ty = cx.typeck_results().expr_ty(let_expr.init);