about summary refs log tree commit diff
diff options
context:
space:
mode:
authorblyxyas <blyxyas@gmail.com>2023-03-14 20:59:39 +0100
committerblyxyas <blyxyas@gmail.com>2023-03-14 20:59:39 +0100
commit3eea49446bae42709b96bd36a0eb2c0966b6b4ac (patch)
tree83826183c190f3edb29e1e1419da2f997fec4219
parentc465bf7f67ff12b9d7246a26ea83f66f0de228da (diff)
downloadrust-3eea49446bae42709b96bd36a0eb2c0966b6b4ac.tar.gz
rust-3eea49446bae42709b96bd36a0eb2c0966b6b4ac.zip
Ignore external macros
-rw-r--r--clippy_lints/src/swap.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs
index 5087c19e5f3..938ca3a6cee 100644
--- a/clippy_lints/src/swap.rs
+++ b/clippy_lints/src/swap.rs
@@ -6,7 +6,8 @@ use clippy_utils::{can_mut_borrow_both, eq_expr_value, in_constant, std_or_core}
 use if_chain::if_chain;
 use rustc_errors::Applicability;
 use rustc_hir::{BinOpKind, Block, Expr, ExprKind, PatKind, QPath, Stmt, StmtKind};
-use rustc_lint::{LateContext, LateLintPass};
+use rustc_lint::{LateContext, LateLintPass, LintContext};
+use rustc_middle::lint::in_external_macro;
 use rustc_middle::ty;
 use rustc_session::{declare_lint_pass, declare_tool_lint};
 use rustc_span::source_map::Spanned;
@@ -75,7 +76,9 @@ declare_lint_pass!(Swap => [MANUAL_SWAP, ALMOST_SWAPPED]);
 impl<'tcx> LateLintPass<'tcx> for Swap {
     fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'_>) {
         check_manual_swap(cx, block);
-        check_suspicious_swap(cx, block);
+        if !in_external_macro(cx.sess(), block.span) {
+            check_suspicious_swap(cx, block);
+        }
         check_xor_swap(cx, block);
     }
 }