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 was referenced Mar 18, 2026
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Mar 23, 2026
Update books ## rust-embedded/book 1 commits in e88aa4403b4bf2071c8df9509160477e40179099..2463edeb8003c5743918b3739a9f6870b86396f5 2026-03-11 17:49:58 UTC to 2026-03-11 17:49:58 UTC - Update teaching material duration for bare-metal Rust (rust-embedded/book#409) ## rust-lang/reference 7 commits in c49e89cc8c7c2c43ca625a8d5b7ad9a53a9ce978..7446bf9697c95d155eef33c6a9d91fbd29a5e359 2026-03-18 01:46:01 UTC to 2026-03-10 18:10:22 UTC - Update `must_use` to use the attribute template (rust-lang/reference#1892) - Add a rule that enum discriminants may not use generic parameters (rust-lang/reference#2206) - Actually move out of Box in moving-out-of-Box test (rust-lang/reference#2204) - Add special cases and links relating to dereferencing boxes (rust-lang/reference#2075) - Move shebang into its own subchapter (rust-lang/reference#2199) - Fields of enums and unions should be allowed to overlap (rust-lang/reference#2168) - [type layout] Clarify size and alignment of pointers to unsized types (rust-lang/reference#2201)
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Mar 24, 2026
Update books ## rust-embedded/book 1 commits in e88aa4403b4bf2071c8df9509160477e40179099..2463edeb8003c5743918b3739a9f6870b86396f5 2026-03-11 17:49:58 UTC to 2026-03-11 17:49:58 UTC - Update teaching material duration for bare-metal Rust (rust-embedded/book#409) ## rust-lang/reference 7 commits in c49e89cc8c7c2c43ca625a8d5b7ad9a53a9ce978..7446bf9697c95d155eef33c6a9d91fbd29a5e359 2026-03-18 01:46:01 UTC to 2026-03-10 18:10:22 UTC - Update `must_use` to use the attribute template (rust-lang/reference#1892) - Add a rule that enum discriminants may not use generic parameters (rust-lang/reference#2206) - Actually move out of Box in moving-out-of-Box test (rust-lang/reference#2204) - Add special cases and links relating to dereferencing boxes (rust-lang/reference#2075) - Move shebang into its own subchapter (rust-lang/reference#2199) - Fields of enums and unions should be allowed to overlap (rust-lang/reference#2168) - [type layout] Clarify size and alignment of pointers to unsized types (rust-lang/reference#2201)
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