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
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
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
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