-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
false positive a=a; a=a
(in clap::Parser
derive)
#10421
Comments
clap-rs/clap#4733 |
Also, neither |
Only in the clap derive since it had its own |
To work around this clippy bug: rust-lang/rust-clippy#10421
To work around this clippy bug: rust-lang/rust-clippy#10421
To work around this clippy bug: rust-lang/rust-clippy#10421
@rustbot claim |
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`)
Task 1 and 3 should be marked as completed to indicate that they are also completed. |
Marked as done! 🎉 |
This fixes a known issue introduced in rust 1.69 clippy that required additional changes to clap. See: rust-lang/rust-clippy#10421 clap-rs/clap#4733
This fixes a known issue introduced in rust 1.69 clippy that required additional changes to clap. See: rust-lang/rust-clippy#10421 clap-rs/clap#4733
Summary
#10177
clippy::almost_swapped
's error message is wrong when triggered in a derive macro. Not sure about other macros.There is no variable called
Parser
, that is the name of the derive macro. Should be:clippy::almost_swapped
triggers when you would be "swapping" the same variable with itself. I.e. the following triggers it:First impression wouldn't be that we're trying to swap
a
witha
since they are the same name. And the generated suggestionstd::mem::swap(&mut a, &mut a)
is silly; breaks aliasing rules.clippy::almost_swapped
triggers within macros in the first place. Should it?Obviously that code above is a little silly, but can be generated in macros, e.g. in
clap::Parser
's derive. Not sure if clippy is supposed to trigger within macros in general--I.e. #10318 ?Lint Name
almost_swapped
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
No error
Clap macro
I tried this code:
Which expands to:
I saw this happen:
I expected to see this happen:
No error
Or
error: this looks like you are trying to swap `__clap_subcommand` and `__clap_subcommand`
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: