This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed
compiler/rustc_passes/src Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -529,15 +529,16 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
529529 let tcx = self . tcx ;
530530 let unconditionally_treat_fields_as_live = self . repr_unconditionally_treats_fields_as_live ;
531531 let has_repr_simd = self . repr_has_repr_simd ;
532+ let effective_visibilities = & tcx. effective_visibilities ( ( ) ) ;
532533 let live_fields = def. fields ( ) . iter ( ) . filter_map ( |f| {
533534 let def_id = f. def_id ;
534535 if unconditionally_treat_fields_as_live || ( f. is_positional ( ) && has_repr_simd) {
535536 return Some ( def_id) ;
536537 }
537- if !tcx . visibility ( f. hir_id . owner . def_id ) . is_public ( ) {
538+ if !effective_visibilities . is_reachable ( f. hir_id . owner . def_id ) {
538539 return None ;
539540 }
540- if tcx . visibility ( def_id) . is_public ( ) { Some ( def_id) } else { None }
541+ if effective_visibilities . is_reachable ( def_id) { Some ( def_id) } else { None }
541542 } ) ;
542543 self . live_symbols . extend ( live_fields) ;
543544
Original file line number Diff line number Diff line change 1+ #![ deny( dead_code) ]
2+
3+ fn main ( ) {
4+ let _ = foo:: S { f : false } ;
5+ }
6+
7+ mod foo {
8+ pub struct S {
9+ pub f : bool , //~ ERROR field `f` is never read
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ error: field `f` is never read
2+ --> $DIR/pub-field-in-priv-mod.rs:9:13
3+ |
4+ LL | pub struct S {
5+ | - field in this struct
6+ LL | pub f: bool,
7+ | ^
8+ |
9+ note: the lint level is defined here
10+ --> $DIR/pub-field-in-priv-mod.rs:1:9
11+ |
12+ LL | #![deny(dead_code)]
13+ | ^^^^^^^^^
14+
15+ error: aborting due to 1 previous error
16+
You can’t perform that action at this time.
0 commit comments