Update must_use to use the attribute template#1892
Merged
traviscross merged 9 commits intorust-lang:masterfrom Mar 18, 2026
Merged
Update must_use to use the attribute template#1892traviscross merged 9 commits intorust-lang:masterfrom
must_use to use the attribute template#1892traviscross merged 9 commits intorust-lang:masterfrom
Conversation
More closely align with the template, and some minor word tweaks.
Collaborator
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
8962eb6 to
40436e7
Compare
Let's adjust the section on `must_use` to follow the editorial direction we've been taking.
The admonition for `must_use` claimed that wrapping a value in a block
expression, as in `{ f() };`, suppresses the `unused_must_use` lint.
Testing against rustc shows this isn't true -- the lint explicitly
looks through block expressions (including `unsafe` and labeled
blocks) to their trailing expression before checking. Let's fix that.
On lang, we recently decided (in rust-lang/rust#147382) that `Result<(), E>` and `ControlFlow<B, ()>` should not trigger the `unused_must_use` lint when the error or break type is uninhabited. The rationale is that an infallible result carries nothing the caller needs to handle. Let's document this.
Now that we support destructuring assignment, using `_ = f()` to suppress a `must_use` lint is also probably idiomatic. Let's mention it.
We have two note admonitions at the bottom of the `must_use` section that weren't associated with any particular rule but, by falling below the final rule without identifiers of their own, appeared to be associated with it. Let's give each of these a rule identifier to make this more clear.
traviscross
approved these changes
Mar 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New rules:
attributes.diagnostics.must_use.syntaxattributes.diagnostics.must_use.duplicates