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.
Warn about unused pub fields in non-pub structs
- Loading branch information
1 parent
c6dd87a
commit 46d55d6
Showing
6 changed files
with
87 additions
and
22 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Unused `pub` fields in non-`pub` structs should also trigger dead code warnings. | ||
// check-pass | ||
|
||
#![warn(dead_code)] | ||
|
||
struct Foo { | ||
a: i32, //~ WARNING: field is never read | ||
pub b: i32, //~ WARNING: field is never read | ||
} | ||
|
||
struct Bar; | ||
|
||
impl Bar { | ||
fn a(&self) -> i32 { 5 } //~ WARNING: associated function is never used | ||
pub fn b(&self) -> i32 { 6 } //~ WARNING: associated function is never used | ||
} | ||
|
||
|
||
fn main() { | ||
let _ = Foo { a: 1, b: 2 }; | ||
let _ = Bar; | ||
} |
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 @@ | ||
warning: field is never read: `a` | ||
--> $DIR/issue-85255.rs:7:5 | ||
| | ||
LL | a: i32, | ||
| ^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/issue-85255.rs:4:9 | ||
| | ||
LL | #![warn(dead_code)] | ||
| ^^^^^^^^^ | ||
|
||
warning: field is never read: `b` | ||
--> $DIR/issue-85255.rs:8:5 | ||
| | ||
LL | pub b: i32, | ||
| ^^^^^^^^^^ | ||
|
||
warning: associated function is never used: `a` | ||
--> $DIR/issue-85255.rs:14:8 | ||
| | ||
LL | fn a(&self) -> i32 { 5 } | ||
| ^ | ||
|
||
warning: associated function is never used: `b` | ||
--> $DIR/issue-85255.rs:15:12 | ||
| | ||
LL | pub fn b(&self) -> i32 { 6 } | ||
| ^ | ||
|
||
warning: 4 warnings emitted | ||
|