@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
2
2
use clippy_utils:: source:: snippet_with_applicability;
3
3
use clippy_utils:: sugg:: Sugg ;
4
4
use 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} ;
6
6
use if_chain:: if_chain;
7
7
use rustc_errors:: Applicability ;
8
8
use rustc_hir:: { BinOpKind , Block , Expr , ExprKind , PatKind , QPath , Stmt , StmtKind } ;
@@ -16,6 +16,8 @@ declare_clippy_lint! {
16
16
/// ### What it does
17
17
/// Checks for manual swapping.
18
18
///
19
+ /// Note that the lint will not be emitted in const blocks, as the suggestion would not be applicable.
20
+ ///
19
21
/// ### Why is this bad?
20
22
/// The `std::mem::swap` function exposes the intent better
21
23
/// without deinitializing or copying either variable.
@@ -138,6 +140,10 @@ fn generate_swap_warning(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>, spa
138
140
139
141
/// Implementation of the `MANUAL_SWAP` lint.
140
142
fn check_manual_swap ( cx : & LateContext < ' _ > , block : & Block < ' _ > ) {
143
+ if in_constant ( cx, block. hir_id ) {
144
+ return ;
145
+ }
146
+
141
147
for w in block. stmts . windows ( 3 ) {
142
148
if_chain ! {
143
149
// let t = foo();
0 commit comments