forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make traits / trait methods detected by the dead code lint!
- Loading branch information
Showing
3 changed files
with
136 additions
and
20 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,29 @@ | ||
#![deny(dead_code)] | ||
|
||
enum Category { | ||
Dead, //~ ERROR variant `Dead` is never constructed | ||
Used, | ||
} | ||
|
||
trait UnusedTrait { //~ ERROR trait `UnusedTrait` is never used | ||
fn this_is_unused(&self) -> Category { | ||
Category::Dead | ||
} | ||
} | ||
|
||
struct UnusedStruct; //~ ERROR struct `UnusedStruct` is never constructed | ||
|
||
impl UnusedTrait for UnusedStruct { | ||
fn this_is_unused(&self) -> Category { | ||
Category::Used | ||
} | ||
} | ||
|
||
mod private { | ||
#[derive(Debug)] | ||
struct UnusedStruct; //~ ERROR struct `UnusedStruct` is never constructed | ||
} | ||
|
||
fn main() { | ||
let _c = Category::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,36 @@ | ||
error: variant `Dead` is never constructed | ||
--> $DIR/issue-41883.rs:4:5 | ||
| | ||
LL | enum Category { | ||
| -------- variant in this enum | ||
LL | Dead, | ||
| ^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/issue-41883.rs:1:9 | ||
| | ||
LL | #![deny(dead_code)] | ||
| ^^^^^^^^^ | ||
|
||
error: trait `UnusedTrait` is never used | ||
--> $DIR/issue-41883.rs:8:7 | ||
| | ||
LL | trait UnusedTrait { | ||
| ^^^^^^^^^^^ | ||
|
||
error: struct `UnusedStruct` is never constructed | ||
--> $DIR/issue-41883.rs:14:8 | ||
| | ||
LL | struct UnusedStruct; | ||
| ^^^^^^^^^^^^ | ||
|
||
error: struct `UnusedStruct` is never constructed | ||
--> $DIR/issue-41883.rs:24:12 | ||
| | ||
LL | struct UnusedStruct; | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: `UnusedStruct` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis | ||
|
||
error: aborting due to 4 previous errors | ||
|