forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 33
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#127017 - mu001999-contrib:dead/enhance, r=p…
…nkfelix Extend rules of dead code analysis for impls for adts to impls for types refer to adts The rules of dead code analysis for impl blocks can be extended to self types which refer to adts. So that we can lint the following unused struct and trait: ```rust struct Foo; //~ ERROR struct `Foo` is never constructed trait Trait { //~ ERROR trait `Trait` is never used fn foo(&self) {} } impl Trait for &Foo {} ``` r? `@pnkfelix`
- Loading branch information
Showing
3 changed files
with
87 additions
and
10 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,45 @@ | ||
#![deny(dead_code)] | ||
|
||
struct Foo; //~ ERROR struct `Foo` is never constructed | ||
|
||
trait Trait { //~ ERROR trait `Trait` is never used | ||
fn foo(&self) {} | ||
} | ||
|
||
impl Trait for Foo {} | ||
|
||
impl Trait for [Foo] {} | ||
impl<const N: usize> Trait for [Foo; N] {} | ||
|
||
impl Trait for *const Foo {} | ||
impl Trait for *mut Foo {} | ||
|
||
impl Trait for &Foo {} | ||
impl Trait for &&Foo {} | ||
impl Trait for &mut Foo {} | ||
|
||
impl Trait for [&Foo] {} | ||
impl Trait for &[Foo] {} | ||
impl Trait for &*const Foo {} | ||
|
||
pub trait Trait2 { | ||
fn foo(&self) {} | ||
} | ||
|
||
impl Trait2 for Foo {} | ||
|
||
impl Trait2 for [Foo] {} | ||
impl<const N: usize> Trait2 for [Foo; N] {} | ||
|
||
impl Trait2 for *const Foo {} | ||
impl Trait2 for *mut Foo {} | ||
|
||
impl Trait2 for &Foo {} | ||
impl Trait2 for &&Foo {} | ||
impl Trait2 for &mut Foo {} | ||
|
||
impl Trait2 for [&Foo] {} | ||
impl Trait2 for &[Foo] {} | ||
impl Trait2 for &*const Foo {} | ||
|
||
fn main() {} |
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,20 @@ | ||
error: struct `Foo` is never constructed | ||
--> $DIR/unused-impl-for-non-adts.rs:3:8 | ||
| | ||
LL | struct Foo; | ||
| ^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/unused-impl-for-non-adts.rs:1:9 | ||
| | ||
LL | #![deny(dead_code)] | ||
| ^^^^^^^^^ | ||
|
||
error: trait `Trait` is never used | ||
--> $DIR/unused-impl-for-non-adts.rs:5:7 | ||
| | ||
LL | trait Trait { | ||
| ^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|