Skip to content

Commit

Permalink
Auto merge of #10499 - blyxyas:fix-almost_swapped, r=giraffate
Browse files Browse the repository at this point in the history
Fix `almost_swapped` false positive (`let mut a = b; a = a`)

Fixes `2` in #10421
changelog: [`almost_swapped`]: Fix false positive when a variable is changed to itself. (`a = a`)
  • Loading branch information
bors committed Mar 14, 2023
2 parents 5941616 + 6631480 commit c465bf7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions clippy_lints/src/swap.rs
Expand Up @@ -190,6 +190,7 @@ fn check_suspicious_swap(cx: &LateContext<'_>, block: &Block<'_>) {
&& first.span.eq_ctxt(second.span)
&& is_same(cx, lhs0, rhs1)
&& is_same(cx, lhs1, rhs0)
&& !is_same(cx, lhs1, rhs1) // Ignore a = b; a = a (#10421)
&& let Some(lhs_sugg) = match &lhs0 {
ExprOrIdent::Expr(expr) => Sugg::hir_opt(cx, expr),
ExprOrIdent::Ident(ident) => Some(Sugg::NonParen(ident.as_str().into())),
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/swap.fixed
Expand Up @@ -186,3 +186,11 @@ const fn issue_9864(mut u: u32) -> u32 {
v = temp;
u + v
}

#[allow(clippy::let_and_return)]
const fn issue_10421(x: u32) -> u32 {
let a = x;
let a = a;
let a = a;
a
}
8 changes: 8 additions & 0 deletions tests/ui/swap.rs
Expand Up @@ -215,3 +215,11 @@ const fn issue_9864(mut u: u32) -> u32 {
v = temp;
u + v
}

#[allow(clippy::let_and_return)]
const fn issue_10421(x: u32) -> u32 {
let a = x;
let a = a;
let a = a;
a
}

0 comments on commit c465bf7

Please sign in to comment.