-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
warning lint on chained assignment #63556
Copy link
Copy link
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
(This is a first impl on https://users.rust-lang.org/t/warn-about-using-the-value-of-an-assignment-expression/31324, thanks to @sourcefrog )
Code like
a = b = 3is a "common" pattern in C, python and other languages. People who are coming to Rust may be surprised to see, that it doesn't work the intended way. There's no warning whatsoever, just a clippy lint:I managed to implement this:
But I have a few questions:
What does the user actually want?
Does he want
1
a = 3; b = 32
a = b == 3The first one only works if the value is
Copyfor obvious reasons.The second one only works if the value implements
PartialEq.I would like to see this in the Rust compiler, what do you think? What is missing? Am I overlooking something? Is everything covered? Would it brake any existing code?