Skip to content

Update must_use to use the attribute template#1892

Merged
traviscross merged 9 commits intorust-lang:masterfrom
ehuss:must_use
Mar 18, 2026
Merged

Update must_use to use the attribute template#1892
traviscross merged 9 commits intorust-lang:masterfrom
ehuss:must_use

Conversation

@ehuss
Copy link
Copy Markdown
Contributor

@ehuss ehuss commented Jun 30, 2025

New rules:

  • attributes.diagnostics.must_use.syntax
  • attributes.diagnostics.must_use.duplicates

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Jun 30, 2025
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 18, 2026

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.

@traviscross traviscross force-pushed the must_use branch 2 times, most recently from 8962eb6 to 40436e7 Compare March 18, 2026 01:14
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 traviscross added this pull request to the merge queue Mar 18, 2026
Merged via the queue into rust-lang:master with commit 7446bf9 Mar 18, 2026
6 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants