Skip to content

Add must_use_without_reason lint - #16592

Merged
rustbot merged 1 commit into
rust-lang:masterfrom
skatromb:must-use-without-note
Sep 19, 2026
Merged

rustbot merged 1 commit into
rust-lang:masterfrom
skatromb:must-use-without-note

Conversation

@skatromb

@skatromb skatromb commented Feb 19, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

PR addresses proposal for adding a lint that warns about a #[must_use] attribute that lacks a reason.
Fixes #16466


Updated after review

Rebased onto current master and addressed all review feedback. The branch is now a single commit.

  • Category style → restriction — the lint is opinionated and restricts an otherwise valid attribute.
  • Renamed must_use_without_note → must_use_without_reason, matching allow_attributes_without_reason. Diagnostic wording uses "reason" throughout.
  • Suggestion placeholder is now #[must_use = "<REASON>"] instead of "/* reason */".
  • must_use_candidate now suggests a message based on is_lint_allowed. By default it is unchanged from master — plain #[must_use], MachineApplicable. Only when must_use_without_reason is enabled at that node does it suggest #[must_use = "<REASON>"], so applying the fix does not immediately trip the other lint. Covered by a scoped module in tests/ui/must_use_candidates.rs, which keeps the existing cases and their .fixed output untouched.
  • in_external_macro guard moved after the item-kind check in all three entry points.

changelog: [must_use_without_reason]: add a lint that warns on #[must_use] attributes without a reason

@rustbot rustbot added the needs-fcp PRs that add, remove, or rename lints and need an FCP label Feb 19, 2026
@github-actions

github-actions Bot commented Feb 19, 2026 •

Copy link
Copy Markdown

Lintcheck changes for f1289a9

Lint Added Removed Changed
clippy::must_use_candidate 0 0 4654
clippy::must_use_without_reason 530 0 0

This comment will be updated if you push new changes

@rustbot

This comment has been minimized.

Comment thread clippy_lints/src/functions/mod.rs Outdated
@skatromb
skatromb force-pushed the must-use-without-note branch 3 times, most recently from dd76a0b to 3a164cc Compare February 27, 2026 17:36
@skatromb
skatromb marked this pull request as ready for review February 27, 2026 21:18
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 27, 2026
@rustbot

rustbot commented Feb 27, 2026

Copy link
Copy Markdown
Collaborator

r? @dswij

rustbot has assigned @dswij.
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: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@rustbot

This comment has been minimized.

@skatromb
skatromb force-pushed the must-use-without-note branch from 3a164cc to 0aca2f3 Compare March 7, 2026 11:33
@rustbot

This comment has been minimized.

@skatromb
skatromb force-pushed the must-use-without-note branch 2 times, most recently from 20eeb87 to 7354069 Compare March 7, 2026 17:40
@skatromb

Copy link
Copy Markdown
Contributor Author

@dswij Hello! Would you be able to review my PR, or should I choose another reviewer?

@skatromb

Copy link
Copy Markdown
Contributor Author

r? @Jarcho
Picking other reviewer, since current doesn't respond

@rustbot rustbot assigned Jarcho and unassigned dswij Mar 27, 2026

@Jarcho Jarcho left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the category change this should also be named must_use_without_reason to match allow_attributes_without_reason.

View changes since this review

Comment thread clippy_lints/src/functions/must_use.rs Outdated
"add the attribute",
format!("#[must_use]\n{indent}"),
Applicability::MachineApplicable,
format!("#[must_use = \"/* reason */\"] \n{indent}"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be suggesting to add a reason in general. You can check if the new lint is enabled using is_lint_allowed and only suggest when it's needed.

Comment thread clippy_lints/src/functions/must_use.rs Outdated
Comment thread clippy_lints/src/functions/must_use.rs Outdated
Comment thread clippy_lints/src/functions/must_use.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Mar 27, 2026
@rustbot

rustbot commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Jarcho

Jarcho commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

@rustbot label lint-nominated

@rustbot rustbot added the lint-nominated Create an FCP-thread on Zulip for this PR label Mar 27, 2026
@rustbot

rustbot commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator

This lint has been nominated for inclusion.

A FCP topic has been created on Zulip.

@rustbot

This comment has been minimized.

@Jarcho

Jarcho commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Ping @skatromb. Do you plan to continue working on this?

@skatromb

skatromb commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi, @Jarcho! I was bit stuck in another project, but will return to this PR in August, if this feels ok for you.

@skatromb
skatromb force-pushed the must-use-without-note branch 3 times, most recently from 681cced to 16290b8 Compare July 30, 2026 11:27
@skatromb
skatromb marked this pull request as ready for review July 30, 2026 11:37
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 30, 2026
@skatromb

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@skatromb
skatromb requested a review from Jarcho July 30, 2026 11:38
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Jul 30, 2026
@rustbot

This comment has been minimized.

@skatromb
skatromb force-pushed the must-use-without-note branch from 16290b8 to f3a4a6e Compare August 13, 2026 06:30
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@skatromb
skatromb force-pushed the must-use-without-note branch from f3a4a6e to 78e11b1 Compare August 20, 2026 06:59
@rustbot

This comment has been minimized.

@skatromb
skatromb requested a review from samueltardieu August 20, 2026 07:08
@skatromb

Copy link
Copy Markdown
Contributor Author

@samueltardieu @Jarcho Rebased on main, fixed your comments, please take a look

@rustbot

This comment has been minimized.

Warns on `#[must_use]` attributes with no accompanying message.
@skatromb
skatromb force-pushed the must-use-without-note branch from 78e11b1 to f1289a9 Compare September 19, 2026 13:11
@rustbot

rustbot commented Sep 19, 2026

Copy link
Copy Markdown
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.

@skatromb

Copy link
Copy Markdown
Contributor Author

@samueltardieu @Jarcho Can you look at PR and approve if everything looks ok for you?

@Jarcho Jarcho left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing with expansion checks. !from_expansion implies !in_external_macro with the former being notably faster.

Ignore this; I misread what was happening.

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Sep 19, 2026

@Jarcho Jarcho left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rustbot
rustbot added this pull request to the merge queue Sep 19, 2026
Merged via the queue into rust-lang:master with commit 9c1bd1f Sep 19, 2026
13 checks passed
@skatromb
skatromb deleted the must-use-without-note branch September 19, 2026 21:01
@skatromb

Copy link
Copy Markdown
Contributor Author

Thank you! ❤️

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

Labels

lint-nominated Create an FCP-thread on Zulip for this PR needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add lint for bare_must_use - #[must_use] without a note

6 participants