Github Warn about unused `pub` fields in non-`pub` structs by FabianWolff · Pull...
source link: https://github.com/rust-lang/rust/pull/85324
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
This pull request fixes #85255. The current implementation of dead code analysis is too prudent because it marks all pub
fields of structs as live, even though they cannot be accessed from outside of the current crate if the struct itself only has restricted or private visibility.
I have changed this behavior to take the containing struct's visibility into account when looking at field visibility and liveness. This also makes dead code warnings more consistent; consider the example given in #85255:
struct Foo { a: i32, pub b: i32, } struct Bar; impl Bar { fn a(&self) -> i32 { 5 } pub fn b(&self) -> i32 { 6 } } fn main() { let _ = Foo { a: 1, b: 2 }; let _ = Bar; }
Current nightly already warns about Bar::b()
, even though it is pub
(but Bar
is not). It should therefore also warn about Foo::b
, which it does with the changes in this PR.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK