-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect unused structs which implement private traits
- Loading branch information
Showing
6 changed files
with
84 additions
and
17 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,34 @@ | ||
#![deny(dead_code)] | ||
|
||
struct Used; | ||
struct Unused; //~ ERROR struct `Unused` is never constructed | ||
|
||
pub trait PubTrait { | ||
fn foo(&self) -> Self; | ||
} | ||
|
||
impl PubTrait for Used { | ||
fn foo(&self) -> Self { Used } | ||
} | ||
|
||
impl PubTrait for Unused { | ||
fn foo(&self) -> Self { Unused } | ||
} | ||
|
||
trait PriTrait { | ||
fn foo(&self) -> Self; | ||
} | ||
|
||
impl PriTrait for Used { | ||
fn foo(&self) -> Self { Used } | ||
} | ||
|
||
impl PriTrait for Unused { | ||
fn foo(&self) -> Self { Unused } | ||
} | ||
|
||
fn main() { | ||
let t = Used; | ||
let _t = <Used as PubTrait>::foo(&t); | ||
let _t = <Used as PriTrait>::foo(&t); | ||
} |
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,14 @@ | ||
error: struct `Unused` is never constructed | ||
--> $DIR/unused-adt-impls-trait.rs:4:8 | ||
| | ||
LL | struct Unused; | ||
| ^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/unused-adt-impls-trait.rs:1:9 | ||
| | ||
LL | #![deny(dead_code)] | ||
| ^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
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