diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2021-05-15 17:56:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-15 17:56:49 +0200 |
| commit | 7a6a25eb2e07267f19abfcf93a0e20c2324c0b1c (patch) | |
| tree | 4ba12fa84caa8ea18002a6c59064bca11eb2d16c /compiler/rustc_codegen_llvm/src | |
| parent | f851f97e8734203a062eb6282fa6314401769c5d (diff) | |
| parent | 46d55d65491ab57e6373d6424f432295eb2eb672 (diff) | |
| download | rust-7a6a25eb2e07267f19abfcf93a0e20c2324c0b1c.tar.gz rust-7a6a25eb2e07267f19abfcf93a0e20c2324c0b1c.zip | |
Rollup merge of #85324 - FabianWolff:issue-85255, r=varkor
Warn about unused `pub` fields in non-`pub` structs
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:
```rust
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.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
0 files changed, 0 insertions, 0 deletions
