@@ -231,7 +231,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
231231 // (i.e. variants, fields, and trait items) inherits from the visibility
232232 // of the enum or trait.
233233 ModuleKind :: Def ( DefKind :: Enum | DefKind :: Trait , def_id, _) => {
234- self . r . visibilities [ & def_id. expect_local ( ) ]
234+ self . r . tcx . visibility ( def_id) . expect_local ( )
235235 }
236236 // Otherwise, the visibility is restricted to the nearest parent `mod` item.
237237 _ => ty:: Visibility :: Restricted (
@@ -399,6 +399,10 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
399399 parent_prefix, use_tree, nested
400400 ) ;
401401
402+ if nested {
403+ self . r . feed_visibility ( self . r . local_def_id ( id) , vis) ;
404+ }
405+
402406 let mut prefix_iter = parent_prefix
403407 . iter ( )
404408 . cloned ( )
@@ -437,8 +441,6 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
437441 let mut source = module_path. pop ( ) . unwrap ( ) ;
438442 let mut type_ns_only = false ;
439443
440- self . r . visibilities . insert ( self . r . local_def_id ( id) , vis) ;
441-
442444 if nested {
443445 // Correctly handle `self`
444446 if source. ident . name == kw:: SelfLower {
@@ -552,7 +554,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
552554 max_vis : Cell :: new ( None ) ,
553555 id,
554556 } ;
555- self . r . visibilities . insert ( self . r . local_def_id ( id ) , vis ) ;
557+
556558 self . add_import ( prefix, kind, use_tree. span , item, root_span, item. id , vis) ;
557559 }
558560 ast:: UseTreeKind :: Nested ( ref items) => {
@@ -629,7 +631,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
629631 let local_def_id = self . r . local_def_id ( item. id ) ;
630632 let def_id = local_def_id. to_def_id ( ) ;
631633
632- self . r . visibilities . insert ( local_def_id, vis) ;
634+ self . r . feed_visibility ( local_def_id, vis) ;
633635
634636 match item. kind {
635637 ItemKind :: Use ( ref use_tree) => {
@@ -753,7 +755,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
753755 let ctor_res =
754756 Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , ctor_kind) , ctor_def_id. to_def_id ( ) ) ;
755757 self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, sp, expansion) ) ;
756- self . r . visibilities . insert ( ctor_def_id, ctor_vis) ;
758+ self . r . feed_visibility ( ctor_def_id, ctor_vis) ;
757759 // We need the field visibility spans also for the constructor for E0603.
758760 self . insert_field_visibilities_local ( ctor_def_id. to_def_id ( ) , vdata) ;
759761
@@ -899,7 +901,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
899901 let vis = self . resolve_visibility ( & item. vis ) ;
900902 let res = Res :: Def ( def_kind, def_id) ;
901903 self . r . define ( parent, item. ident , ns, ( res, vis, item. span , expansion) ) ;
902- self . r . visibilities . insert ( local_def_id, vis) ;
904+ self . r . feed_visibility ( local_def_id, vis) ;
903905 }
904906
905907 fn build_reduced_graph_for_block ( & mut self , block : & Block ) {
@@ -1233,7 +1235,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
12331235 self . r . check_reserved_macro_name ( ident, res) ;
12341236 self . insert_unused_macro ( ident, def_id, item. id ) ;
12351237 }
1236- self . r . visibilities . insert ( def_id, vis) ;
1238+ self . r . feed_visibility ( def_id, vis) ;
12371239 let scope = self . r . arenas . alloc_macro_rules_scope ( MacroRulesScope :: Binding (
12381240 self . r . arenas . alloc_macro_rules_binding ( MacroRulesBinding {
12391241 parent_macro_rules_scope : parent_scope. macro_rules ,
@@ -1257,7 +1259,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
12571259 self . insert_unused_macro ( ident, def_id, item. id ) ;
12581260 }
12591261 self . r . define ( module, ident, MacroNS , ( res, vis, span, expansion) ) ;
1260- self . r . visibilities . insert ( def_id, vis) ;
1262+ self . r . feed_visibility ( def_id, vis) ;
12611263 self . parent_scope . macro_rules
12621264 }
12631265 }
@@ -1359,7 +1361,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
13591361 // Trait impl item visibility is inherited from its trait when not specified
13601362 // explicitly. In that case we cannot determine it here in early resolve,
13611363 // so we leave a hole in the visibility table to be filled later.
1362- self . r . visibilities . insert ( local_def_id, vis) ;
1364+ self . r . feed_visibility ( local_def_id, vis) ;
13631365 }
13641366
13651367 if ctxt == AssocCtxt :: Trait {
@@ -1438,7 +1440,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
14381440 self . visit_invoc ( sf. id ) ;
14391441 } else {
14401442 let vis = self . resolve_visibility ( & sf. vis ) ;
1441- self . r . visibilities . insert ( self . r . local_def_id ( sf. id ) , vis) ;
1443+ self . r . feed_visibility ( self . r . local_def_id ( sf. id ) , vis) ;
14421444 visit:: walk_field_def ( self , sf) ;
14431445 }
14441446 }
@@ -1460,7 +1462,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
14601462 let res = Res :: Def ( DefKind :: Variant , def_id. to_def_id ( ) ) ;
14611463 let vis = self . resolve_visibility ( & variant. vis ) ;
14621464 self . r . define ( parent, ident, TypeNS , ( res, vis, variant. span , expn_id) ) ;
1463- self . r . visibilities . insert ( def_id, vis) ;
1465+ self . r . feed_visibility ( def_id, vis) ;
14641466
14651467 // If the variant is marked as non_exhaustive then lower the visibility to within the crate.
14661468 let ctor_vis =
@@ -1476,7 +1478,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
14761478 let ctor_res =
14771479 Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , ctor_kind) , ctor_def_id. to_def_id ( ) ) ;
14781480 self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, variant. span , expn_id) ) ;
1479- self . r . visibilities . insert ( ctor_def_id, ctor_vis) ;
1481+ self . r . feed_visibility ( ctor_def_id, ctor_vis) ;
14801482 }
14811483
14821484 // Record field names for error reporting.
0 commit comments