Skip to content

Commit 3eea494

Browse files
committed
Ignore external macros
1 parent c465bf7 commit 3eea494

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

clippy_lints/src/swap.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use clippy_utils::{can_mut_borrow_both, eq_expr_value, in_constant, std_or_core}
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
88
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, PatKind, QPath, Stmt, StmtKind};
9-
use rustc_lint::{LateContext, LateLintPass};
9+
use rustc_lint::{LateContext, LateLintPass, LintContext};
10+
use rustc_middle::lint::in_external_macro;
1011
use rustc_middle::ty;
1112
use rustc_session::{declare_lint_pass, declare_tool_lint};
1213
use rustc_span::source_map::Spanned;
@@ -75,7 +76,9 @@ declare_lint_pass!(Swap => [MANUAL_SWAP, ALMOST_SWAPPED]);
7576
impl<'tcx> LateLintPass<'tcx> for Swap {
7677
fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'_>) {
7778
check_manual_swap(cx, block);
78-
check_suspicious_swap(cx, block);
79+
if !in_external_macro(cx.sess(), block.span) {
80+
check_suspicious_swap(cx, block);
81+
}
7982
check_xor_swap(cx, block);
8083
}
8184
}

0 commit comments

Comments
 (0)