-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect pub structs never constructed even though they impl pub trait …
…with assoc constants
- Loading branch information
Showing
3 changed files
with
60 additions
and
2 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
32 changes: 32 additions & 0 deletions
32
tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.rs
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,32 @@ | ||
#![deny(dead_code)] | ||
|
||
struct T1; //~ ERROR struct `T1` is never constructed | ||
pub struct T2(i32); //~ ERROR struct `T2` is never constructed | ||
|
||
trait Trait1 { //~ ERROR trait `Trait1` is never used | ||
const UNUSED: i32; | ||
fn unused(&self) {} | ||
} | ||
|
||
pub trait Trait2 { | ||
const MAY_USED: i32; | ||
fn may_used(&self) {} | ||
} | ||
|
||
impl Trait1 for T1 { | ||
const UNUSED: i32 = 0; | ||
} | ||
|
||
impl Trait1 for T2 { | ||
const UNUSED: i32 = 0; | ||
} | ||
|
||
impl Trait2 for T1 { | ||
const MAY_USED: i32 = 0; | ||
} | ||
|
||
impl Trait2 for T2 { | ||
const MAY_USED: i32 = 0; | ||
} | ||
|
||
fn main() {} |
26 changes: 26 additions & 0 deletions
26
tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.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,26 @@ | ||
error: struct `T1` is never constructed | ||
--> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:3:8 | ||
| | ||
LL | struct T1; | ||
| ^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:1:9 | ||
| | ||
LL | #![deny(dead_code)] | ||
| ^^^^^^^^^ | ||
|
||
error: struct `T2` is never constructed | ||
--> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:4:12 | ||
| | ||
LL | pub struct T2(i32); | ||
| ^^ | ||
|
||
error: trait `Trait1` is never used | ||
--> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:6:7 | ||
| | ||
LL | trait Trait1 { | ||
| ^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|