-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Warning for unused arithmetic expressions #50124
Copy link
Copy link
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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.
Description
Activity
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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.
After having spent a day tracking down this bug, and recalling all the past times the same thing has bitten me, I'd like to propose a lint unused results of arithmetic expressions. Consider the following code:
This code currently compiles with no warnings (given a suitable
enum Foo). However, bugs like these can be extremely hard to track down. They can often be hard to spot, especially when going through methods likesaturating_subwhich do not modifyself, but instead return the new result (e.g.,delta = delta.saturating_sub(x)is necessary).It would be really neat to have a warning about unused arithmetic expressions (ideally one that also handles
saturating_sub). I don't think there are generally cases where not using the result of an arithmetic expression is what the developer intended to do. This also complements theunused_variablesandunused_mutlints quite nicely.