-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[double_must_use]: make the lint machine-applicable in single-attribute case
#17144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
samueltardieu
merged 1 commit into
rust-lang:master
from
LebedevRI:double_must_use-fixit
Jun 3, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #![warn(clippy::double_must_use)] | ||
| #![expect(clippy::result_unit_err)] | ||
| #![feature(never_type)] | ||
|
|
||
| use std::ops::ControlFlow; | ||
|
|
||
| pub fn must_use_result() -> Result<(), ()> { | ||
| //~^ double_must_use | ||
|
|
||
| unimplemented!(); | ||
| } | ||
|
|
||
| pub fn must_use_tuple() -> (Result<(), ()>, u8) { | ||
| //~^ double_must_use | ||
|
|
||
| unimplemented!(); | ||
| } | ||
|
|
||
| pub fn must_use_array() -> [Result<(), ()>; 1] { | ||
| //~^ double_must_use | ||
|
|
||
| unimplemented!(); | ||
| } | ||
|
|
||
| #[must_use = "With note"] | ||
| pub fn must_use_with_note() -> Result<(), ()> { | ||
| unimplemented!(); | ||
| } | ||
|
|
||
| // vvvv Should not lint (#10486) | ||
| #[must_use] | ||
| async fn async_must_use() -> usize { | ||
| unimplemented!(); | ||
| } | ||
|
|
||
| async fn async_must_use_result() -> Result<(), ()> { | ||
| //~^ double_must_use | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[must_use] | ||
| pub fn must_use_result_with_uninhabited() -> Result<(), !> { | ||
| unimplemented!(); | ||
| } | ||
|
|
||
| #[must_use] | ||
| pub struct T; | ||
|
|
||
| pub fn must_use_result_with_uninhabited_2() -> Result<T, !> { | ||
| //~^ double_must_use | ||
| unimplemented!(); | ||
| } | ||
|
|
||
| #[must_use] | ||
| pub fn must_use_controlflow_with_uninhabited() -> ControlFlow<std::convert::Infallible> { | ||
| unimplemented!(); | ||
| } | ||
|
|
||
| pub fn must_use_controlflow_with_uninhabited_2() -> ControlFlow<std::convert::Infallible, T> { | ||
| //~^ double_must_use | ||
| unimplemented!(); | ||
| } | ||
|
|
||
| fn main() {} |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,52 +1,64 @@ | ||
| error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` | ||
| --> tests/ui/double_must_use.rs:8:1 | ||
| | | ||
| LL | #[must_use] | ||
| | ----------- help: remove the attribute | ||
| LL | pub fn must_use_result() -> Result<(), ()> { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: either add some descriptive message or remove the attribute | ||
| = note: alternatively, you may add an explicit reason to the `must_use` attribute | ||
| = note: `-D clippy::double-must-use` implied by `-D warnings` | ||
| = help: to override `-D warnings` add `#[allow(clippy::double_must_use)]` | ||
|
|
||
| error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` | ||
| --> tests/ui/double_must_use.rs:15:1 | ||
| | | ||
| LL | #[must_use] | ||
| | ----------- help: remove the attribute | ||
| LL | pub fn must_use_tuple() -> (Result<(), ()>, u8) { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: either add some descriptive message or remove the attribute | ||
| = note: alternatively, you may add an explicit reason to the `must_use` attribute | ||
|
|
||
| error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` | ||
| --> tests/ui/double_must_use.rs:22:1 | ||
| | | ||
| LL | #[must_use] | ||
| | ----------- help: remove the attribute | ||
| LL | pub fn must_use_array() -> [Result<(), ()>; 1] { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: either add some descriptive message or remove the attribute | ||
| = note: alternatively, you may add an explicit reason to the `must_use` attribute | ||
|
|
||
| error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` | ||
| --> tests/ui/double_must_use.rs:40:1 | ||
| | | ||
| LL | #[must_use] | ||
| | ----------- help: remove the attribute | ||
| LL | async fn async_must_use_result() -> Result<(), ()> { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: either add some descriptive message or remove the attribute | ||
| = note: alternatively, you may add an explicit reason to the `must_use` attribute | ||
|
|
||
| error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` | ||
| --> tests/ui/double_must_use.rs:55:1 | ||
| | | ||
| LL | #[must_use] | ||
| | ----------- help: remove the attribute | ||
| LL | pub fn must_use_result_with_uninhabited_2() -> Result<T, !> { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: either add some descriptive message or remove the attribute | ||
| = note: alternatively, you may add an explicit reason to the `must_use` attribute | ||
|
|
||
| error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` | ||
| --> tests/ui/double_must_use.rs:66:1 | ||
| | | ||
| LL | #[must_use] | ||
| | ----------- help: remove the attribute | ||
| LL | pub fn must_use_controlflow_with_uninhabited_2() -> ControlFlow<std::convert::Infallible, T> { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: either add some descriptive message or remove the attribute | ||
| = note: alternatively, you may add an explicit reason to the `must_use` attribute | ||
|
|
||
| error: aborting due to 6 previous errors | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #![warn(clippy::double_must_use)] | ||
| #![expect(clippy::result_unit_err)] | ||
| #![feature(never_type)] | ||
|
|
||
| #[cfg_attr(all(), must_use, deprecated)] | ||
| pub fn issue_12320() -> Result<(), ()> { | ||
| //~^ double_must_use | ||
| unimplemented!(); | ||
| } | ||
|
|
||
| #[cfg_attr(all(), deprecated, must_use)] | ||
| pub fn issue_12320_2() -> Result<(), ()> { | ||
| //~^ double_must_use | ||
| unimplemented!(); | ||
| } | ||
|
|
||
| fn main() {} |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` | ||
| --> tests/ui/double_must_use_unfixable.rs:6:1 | ||
| | | ||
| LL | pub fn issue_12320() -> Result<(), ()> { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| help: remove `must_use` | ||
| --> tests/ui/double_must_use_unfixable.rs:5:19 | ||
| | | ||
| LL | #[cfg_attr(all(), must_use, deprecated)] | ||
| | ^^^^^^^^ | ||
| = note: alternatively, you may add an explicit reason to the `must_use` attribute | ||
| = note: `-D clippy::double-must-use` implied by `-D warnings` | ||
| = help: to override `-D warnings` add `#[allow(clippy::double_must_use)]` | ||
|
|
||
| error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` | ||
| --> tests/ui/double_must_use_unfixable.rs:12:1 | ||
| | | ||
| LL | pub fn issue_12320_2() -> Result<(), ()> { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| help: remove `must_use` | ||
| --> tests/ui/double_must_use_unfixable.rs:11:31 | ||
| | | ||
| LL | #[cfg_attr(all(), deprecated, must_use)] | ||
| | ^^^^^^^^ | ||
| = note: alternatively, you may add an explicit reason to the `must_use` attribute | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
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.
Uh oh!
There was an error while loading. Please reload this page.