forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
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#127107 - mu001999-contrib:dead/enhance-2, r…
…=pnkfelix Improve dead code analysis Fixes rust-lang#120770 1. check impl items later if self ty is private although the trait method is public, cause we must use the ty firstly if it's private 2. mark the adt live if it appears in pattern, like generic argument, this implies the use of the adt 3. based on the above, we can handle the case that private adts impl Default, so that we don't need adding rustc_trivial_field_reads on Default, and the logic in should_ignore_item r? ``@pnkfelix``
- Loading branch information
Showing
21 changed files
with
164 additions
and
60 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
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
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 |
---|---|---|
|
@@ -4,8 +4,8 @@ | |
|
||
#![deny(dead_code)] | ||
|
||
#[allow(dead_code)] | ||
struct Foo { | ||
#[allow(dead_code)] | ||
inner: u32, | ||
} | ||
|
||
|
37 changes: 37 additions & 0 deletions
37
tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.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,37 @@ | ||
#![deny(dead_code)] | ||
|
||
struct Foo(u8); //~ ERROR struct `Foo` is never constructed | ||
|
||
enum Bar { //~ ERROR enum `Bar` is never used | ||
Var1(u8), | ||
Var2(u8), | ||
} | ||
|
||
pub trait Tr1 { | ||
fn f1() -> Self; | ||
} | ||
|
||
impl Tr1 for Foo { | ||
fn f1() -> Foo { | ||
let f = Foo(0); | ||
let Foo(tag) = f; | ||
Foo(tag) | ||
} | ||
} | ||
|
||
impl Tr1 for Bar { | ||
fn f1() -> Bar { | ||
let b = Bar::Var1(0); | ||
let b = if let Bar::Var1(_) = b { | ||
Bar::Var1(0) | ||
} else { | ||
Bar::Var2(0) | ||
}; | ||
match b { | ||
Bar::Var1(_) => Bar::Var2(0), | ||
Bar::Var2(_) => Bar::Var1(0), | ||
} | ||
} | ||
} | ||
|
||
fn main() {} |
20 changes: 20 additions & 0 deletions
20
tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.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,20 @@ | ||
error: struct `Foo` is never constructed | ||
--> $DIR/lint-unused-adt-appeared-in-pattern.rs:3:8 | ||
| | ||
LL | struct Foo(u8); | ||
| ^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/lint-unused-adt-appeared-in-pattern.rs:1:9 | ||
| | ||
LL | #![deny(dead_code)] | ||
| ^^^^^^^^^ | ||
|
||
error: enum `Bar` is never used | ||
--> $DIR/lint-unused-adt-appeared-in-pattern.rs:5:6 | ||
| | ||
LL | enum Bar { | ||
| ^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
32 changes: 32 additions & 0 deletions
32
tests/ui/lint/dead-code/not-lint-used-adt-appeared-in-pattern.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 @@ | ||
//@ check-pass | ||
|
||
#![deny(dead_code)] | ||
|
||
#[repr(u8)] | ||
#[derive(Copy, Clone, Debug)] | ||
pub enum RecordField { | ||
Target = 1, | ||
Level, | ||
Module, | ||
File, | ||
Line, | ||
NumArgs, | ||
} | ||
|
||
unsafe trait Pod {} | ||
|
||
#[repr(transparent)] | ||
struct RecordFieldWrapper(RecordField); | ||
|
||
unsafe impl Pod for RecordFieldWrapper {} | ||
|
||
fn try_read<T: Pod>(buf: &[u8]) -> T { | ||
unsafe { std::ptr::read_unaligned(buf.as_ptr() as *const T) } | ||
} | ||
|
||
pub fn foo(buf: &[u8]) -> RecordField { | ||
let RecordFieldWrapper(tag) = try_read(buf); | ||
tag | ||
} | ||
|
||
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
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
Oops, something went wrong.