forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
in which we lint
#[must_use]
functions with discardable return type
Resolves rust-lang#54828.
- Loading branch information
1 parent
4efdc04
commit 652ac8f
Showing
4 changed files
with
120 additions
and
1 deletion.
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
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,31 @@ | ||
#![allow(dead_code)] | ||
#![deny(unused_attributes)] | ||
|
||
#[must_use] | ||
fn truth() {} | ||
|
||
#[must_use] | ||
fn pain() -> () {} | ||
|
||
#[must_use] | ||
fn dignity() -> ! { panic!("despair"); } | ||
|
||
struct Fear{} | ||
|
||
impl Fear { | ||
#[must_use] fn bravery() {} | ||
} | ||
|
||
trait Suspicion { | ||
#[must_use] fn inspect(); | ||
} | ||
|
||
impl Suspicion for Fear { | ||
// FIXME: it's actually rather problematic for this to get the unused-attributes | ||
// lint on account of the return type—the unused-attributes lint should fire | ||
// here, but it should be because `#[must_use]` needs to go on the trait | ||
// definition, not the impl (Issue #48486) | ||
#[must_use] fn inspect() {} | ||
} | ||
|
||
fn main() {} |
48 changes: 48 additions & 0 deletions
48
src/test/ui/lint/issue-54828-unused-must-use-attribute.stderr
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,48 @@ | ||
error: unused attribute | ||
--> $DIR/issue-54828-unused-must-use-attribute.rs:4:1 | ||
| | ||
LL | #[must_use] | ||
| ^^^^^^^^^^^ help: remove it | ||
LL | fn truth() {} | ||
| - the return type `()` can be discarded | ||
| | ||
note: lint level defined here | ||
--> $DIR/issue-54828-unused-must-use-attribute.rs:2:9 | ||
| | ||
LL | #![deny(unused_attributes)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: unused attribute | ||
--> $DIR/issue-54828-unused-must-use-attribute.rs:7:1 | ||
| | ||
LL | #[must_use] | ||
| ^^^^^^^^^^^ help: remove it | ||
LL | fn pain() -> () {} | ||
| -- the return type `()` can be discarded | ||
|
||
error: unused attribute | ||
--> $DIR/issue-54828-unused-must-use-attribute.rs:10:1 | ||
| | ||
LL | #[must_use] | ||
| ^^^^^^^^^^^ help: remove it | ||
LL | fn dignity() -> ! { panic!("despair"); } | ||
| - the return type `!` can be discarded | ||
|
||
error: unused attribute | ||
--> $DIR/issue-54828-unused-must-use-attribute.rs:16:5 | ||
| | ||
LL | #[must_use] fn bravery() {} | ||
| ^^^^^^^^^^^ - the return type `()` can be discarded | ||
| | | ||
| help: remove it | ||
|
||
error: unused attribute | ||
--> $DIR/issue-54828-unused-must-use-attribute.rs:28:5 | ||
| | ||
LL | #[must_use] fn inspect() {} | ||
| ^^^^^^^^^^^ - the return type `()` can be discarded | ||
| | | ||
| help: remove it | ||
|
||
error: aborting due to 5 previous errors | ||
|