-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #55663 - varkor:must_use-traits, r=estebank
Allow #[must_use] on traits Addresses #55506, but we'll probably want to add it to some library traits like `Iterator` before the issue is considered fixed. Fixes #51560. `#[must_use]` is already permitted on traits, with no effect, so this seems like a bug fix, but I might be overlooking something. This currently warns for `impl Trait` or `dyn Trait` when the `Trait` is `#[must_use]` (although I don't think the latter is currently possible, so it's simply future-proofed).
- Loading branch information
Showing
3 changed files
with
79 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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,22 @@ | ||
#![deny(unused_must_use)] | ||
|
||
#[must_use] | ||
trait Critical {} | ||
|
||
trait NotSoCritical {} | ||
|
||
trait DecidedlyUnimportant {} | ||
|
||
struct Anon; | ||
|
||
impl Critical for Anon {} | ||
impl NotSoCritical for Anon {} | ||
impl DecidedlyUnimportant for Anon {} | ||
|
||
fn get_critical() -> impl NotSoCritical + Critical + DecidedlyUnimportant { | ||
Anon {} | ||
} | ||
|
||
fn main() { | ||
get_critical(); //~ ERROR unused implementer of `Critical` that must be used | ||
} |
This file contains 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,14 @@ | ||
error: unused implementer of `Critical` that must be used | ||
--> $DIR/must_use-trait.rs:21:5 | ||
| | ||
LL | get_critical(); //~ ERROR unused implementer of `Critical` that must be used | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/must_use-trait.rs:1:9 | ||
| | ||
LL | #![deny(unused_must_use)] | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|