-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Warn on useless bindings like let v2 = v1.sort(); #71432
Copy link
Copy link
Closed
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.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.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.
I've seen a lot of beginning Rust programmers make a mistake similar to the program below, which compiles and runs without warning:
The bug in this program is hard for new Rust programmers to spot. The compiler should help them, by warning that
x.sort()does not return a value.This could be done with a new attribute
#[must_not_use], applied to functions likesort. This would be the inverse ofmust_use: It would warn only if the result of the function is used. Likemust_use, it would take an optional argument that provides an additional diagnostic message.(Bikeshed:
must_not_usemay be a confusing name. Other suggestions welcome.)Or perhaps any assignment
let foo = expr;whereexprhas type()should cause a warning by default. This would be a more general solution, catching more possible errors but also potentially causing more disruption. The warnings in this case might be less helpful, because they wouldn't include suggestions tailored to specific functions.