@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
22use clippy_utils:: source:: snippet_with_applicability;
33use clippy_utils:: sugg:: Sugg ;
44use clippy_utils:: ty:: is_type_diagnostic_item;
5- use clippy_utils:: { can_mut_borrow_both, eq_expr_value, std_or_core} ;
5+ use clippy_utils:: { can_mut_borrow_both, eq_expr_value, in_constant , std_or_core} ;
66use if_chain:: if_chain;
77use rustc_errors:: Applicability ;
88use rustc_hir:: { BinOpKind , Block , Expr , ExprKind , PatKind , QPath , Stmt , StmtKind } ;
@@ -16,6 +16,8 @@ declare_clippy_lint! {
1616 /// ### What it does
1717 /// Checks for manual swapping.
1818 ///
19+ /// Note that the lint will not be emitted in const blocks, as the suggestion would not be applicable.
20+ ///
1921 /// ### Why is this bad?
2022 /// The `std::mem::swap` function exposes the intent better
2123 /// without deinitializing or copying either variable.
@@ -138,6 +140,10 @@ fn generate_swap_warning(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>, spa
138140
139141/// Implementation of the `MANUAL_SWAP` lint.
140142fn check_manual_swap ( cx : & LateContext < ' _ > , block : & Block < ' _ > ) {
143+ if in_constant ( cx, block. hir_id ) {
144+ return ;
145+ }
146+
141147 for w in block. stmts . windows ( 3 ) {
142148 if_chain ! {
143149 // let t = foo();
0 commit comments