Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

almost_swapped with let #8151

Closed
xNxExOx opened this issue Dec 20, 2021 · 1 comment · Fixed by #10177
Closed

almost_swapped with let #8151

xNxExOx opened this issue Dec 20, 2021 · 1 comment · Fixed by #10177
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@xNxExOx
Copy link

xNxExOx commented Dec 20, 2021

Summary

a = b;
b = a;

produces lint correctly, but adding let does not:

let a = b;
let b = a;

Lint Name

almost_swapped

Reproducer

I tried this code:

let mut a = 1;
let mut b = 2;
let a = b;
let b = a;

I expected to see this happen:

Instead, this happened:

error: this looks like you are trying to swap `a` and `b`
   --> src\patches\inventory\filter.rs:255:5
    |
3  | /     let a = b;
4  | |     let b = a;
    | |_________^ help: try: `std::mem::swap(&mut a, &mut b)`
    |
    = note: `#[deny(clippy::almost_swapped)]` on by default
    = note: or maybe you should use `std::mem::replace`?
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#almost_swapped

Version

rustc 1.59.0-nightly (efec54529 2021-12-04)
binary: rustc
commit-hash: efec545293b9263be9edfb283a7aa66350b3acbf
commit-date: 2021-12-04
host: x86_64-pc-windows-msvc
release: 1.59.0-nightly
LLVM version: 13.0.0
@xNxExOx xNxExOx added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Dec 20, 2021
@DevAccentor
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
2 participants