Skip to content

Make the suggestion message of unused_must_use scarier. - #162819

Open
kpreid wants to merge 1 commit into
rust-lang:mainfrom
kpreid:must-use-advice
Open

kpreid wants to merge 1 commit into
rust-lang:mainfrom
kpreid:must-use-advice

Conversation

@kpreid

@kpreid kpreid commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

The old message, “help: use let _ = ... to ignore the resulting value”, contains no indication that this is something that you might not want to do, and in fact can be read as saying that one should do this.

The new message, “help: if you wish to disregard this recommendation and immediately drop the value, use let _ = ...”, is intended to make it clear that this is a choice, and choosing it has the particular effect of immediately dropping the value.

A possible further improvement, not part of this change, might be to distinguish between types that are must_use and have a destructor (whose side-effects are likely relevant), and types that are must_use and do not have a destructor, where the timing is irrelevant and the consequence is just ignoring information that was provided. However, not every destructor is relevant to must_use; for example, Result<(), Box<dyn Error>> has a destructor and is must_use, but the destructor is only managing memory for the error value and it has no side effects relevant to the caller (unless the error in the box has side effects of its own).

Inspired by #t-lang > Lint for assigning drop guards to _

@rustbot label +A-lints +L-unused_must_use

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 15, 2026
@rustbot

rustbot commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

r? @jackh726

rustbot has assigned @jackh726.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 76 candidates
  • Random selection from 19 candidates

@rustbot rustbot added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. L-unused_must_use Lint: unused_must_use labels Sep 15, 2026
@kpreid
kpreid force-pushed the must-use-advice branch 2 times, most recently from beef742 to d08786b Compare September 15, 2026 19:46
@rust-bors

This comment has been minimized.

The old message, “help: use `let _ = ...` to ignore the resulting
value”, contains no indication that this is something that you might
not want to do, and in fact can be read as saying that one *should*
do this.

The new message, “if you wish to disregard this recommendation and
immediately drop the value, use `let _ = ...`”, is intended to make it
clear that this is a choice, and choosing it has the particular effect
of immediately dropping the value.

A possible further improvement, not part of this change, might be to
distinguish between types that are `must_use` and have a destructor
(whose side-effects are likely relevant), and types that are `must_use`
and do not have a destructor, where the timing is irrelevant and the
consequence is just ignoring information that was provided. However,
not every destructor is relevant to `must_use`; for example,
`Result<(), Box<dyn Error>>` has a destructor and is `must_use`, but
the destructor is only managing memory for the error value and it has
no side effects relevant to the caller (unless the error in the box
has side effects of its own).
@rustbot

rustbot commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main 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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. L-unused_must_use Lint: unused_must_use S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants