-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Missing 'unused assignment' warning with += operator on String #102453
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.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.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.
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.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Given the following code (playground):
The current output shows no warnings.
Ideally the output should look like:
Switching to
s = s + "B", or changing the variable tou32, makes the desired warning appear. And indeed there are types for which+=might be used for external side effects alone. ButStringdoes not really "do" anything, sosshould be considered unused afters += "B".Perhaps I want something like
#[must_use_self]onString::add_assign: similar to#[must_use]except that it applies toselfafter the call, rather than to the method's return value.Somewhat related to #63054.