forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#126276 - mu001999-contrib:dead/enhance, r=fee1-dead Detect pub structs never constructed even though they impl pub trait with assoc constants Extend dead code analysis to impl items of pub assoc constants. <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> -->
- Loading branch information
Showing
3 changed files
with
80 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
52 changes: 52 additions & 0 deletions
52
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,52 @@ | ||
#![deny(dead_code)] | ||
|
||
struct T1; //~ ERROR struct `T1` is never constructed | ||
pub struct T2(i32); //~ ERROR struct `T2` is never constructed | ||
struct T3; | ||
|
||
trait Trait1 { //~ ERROR trait `Trait1` is never used | ||
const UNUSED: i32; | ||
fn unused(&self) {} | ||
fn construct_self() -> Self; | ||
} | ||
|
||
pub trait Trait2 { | ||
const USED: i32; | ||
fn used(&self) {} | ||
} | ||
|
||
pub trait Trait3 { | ||
const USED: i32; | ||
fn construct_self() -> Self; | ||
} | ||
|
||
impl Trait1 for T1 { | ||
const UNUSED: i32 = 0; | ||
fn construct_self() -> Self { | ||
Self | ||
} | ||
} | ||
|
||
impl Trait1 for T2 { | ||
const UNUSED: i32 = 0; | ||
fn construct_self() -> Self { | ||
T2(0) | ||
} | ||
} | ||
|
||
impl Trait2 for T1 { | ||
const USED: i32 = 0; | ||
} | ||
|
||
impl Trait2 for T2 { | ||
const USED: i32 = 0; | ||
} | ||
|
||
impl Trait3 for T3 { | ||
const USED: i32 = 0; | ||
fn construct_self() -> Self { | ||
Self | ||
} | ||
} | ||
|
||
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:7:7 | ||
| | ||
LL | trait Trait1 { | ||
| ^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|