Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Test for #[must_use] on traits
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 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
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 | ||
|