@@ -236,7 +236,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
236236 // (i.e. variants, fields, and trait items) inherits from the visibility
237237 // of the enum or trait.
238238 ModuleKind :: Def ( DefKind :: Enum | DefKind :: Trait , def_id, _) => {
239- self . r . visibilities [ & def_id. expect_local ( ) ]
239+ self . r . tcx . visibility ( def_id) . expect_local ( )
240240 }
241241 // Otherwise, the visibility is restricted to the nearest parent `mod` item.
242242 _ => ty:: Visibility :: Restricted (
@@ -404,6 +404,10 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
404404 parent_prefix, use_tree, nested
405405 ) ;
406406
407+ if nested {
408+ self . r . feed_visibility ( self . r . local_def_id ( id) , vis) ;
409+ }
410+
407411 let mut prefix_iter = parent_prefix
408412 . iter ( )
409413 . cloned ( )
@@ -442,8 +446,6 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
442446 let mut source = module_path. pop ( ) . unwrap ( ) ;
443447 let mut type_ns_only = false ;
444448
445- self . r . visibilities . insert ( self . r . local_def_id ( id) , vis) ;
446-
447449 if nested {
448450 // Correctly handle `self`
449451 if source. ident . name == kw:: SelfLower {
@@ -557,7 +559,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
557559 max_vis : Cell :: new ( None ) ,
558560 id,
559561 } ;
560- self . r . visibilities . insert ( self . r . local_def_id ( id ) , vis ) ;
562+
561563 self . add_import ( prefix, kind, use_tree. span , item, root_span, item. id , vis) ;
562564 }
563565 ast:: UseTreeKind :: Nested ( ref items) => {
@@ -636,7 +638,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
636638 let def_kind = self . r . tcx . def_kind ( def_id) ;
637639 let res = Res :: Def ( def_kind, def_id) ;
638640
639- self . r . visibilities . insert ( local_def_id, vis) ;
641+ self . r . feed_visibility ( local_def_id, vis) ;
640642
641643 match item. kind {
642644 ItemKind :: Use ( ref use_tree) => {
@@ -753,7 +755,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
753755 let ctor_def_id = self . r . local_def_id ( ctor_node_id) ;
754756 let ctor_res = self . res ( ctor_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
@@ -897,7 +899,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
897899 let expansion = self . parent_scope . expansion ;
898900 let vis = self . resolve_visibility ( & item. vis ) ;
899901 self . r . define ( parent, item. ident , ns, ( self . res ( def_id) , vis, item. span , expansion) ) ;
900- self . r . visibilities . insert ( local_def_id, vis) ;
902+ self . r . feed_visibility ( local_def_id, vis) ;
901903 }
902904
903905 fn build_reduced_graph_for_block ( & mut self , block : & Block ) {
@@ -1228,7 +1230,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
12281230 self . r . check_reserved_macro_name ( ident, res) ;
12291231 self . insert_unused_macro ( ident, def_id, item. id ) ;
12301232 }
1231- self . r . visibilities . insert ( def_id, vis) ;
1233+ self . r . feed_visibility ( def_id, vis) ;
12321234 let scope = self . r . arenas . alloc_macro_rules_scope ( MacroRulesScope :: Binding (
12331235 self . r . arenas . alloc_macro_rules_binding ( MacroRulesBinding {
12341236 parent_macro_rules_scope : parent_scope. macro_rules ,
@@ -1252,7 +1254,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
12521254 self . insert_unused_macro ( ident, def_id, item. id ) ;
12531255 }
12541256 self . r . define ( module, ident, MacroNS , ( res, vis, span, expansion) ) ;
1255- self . r . visibilities . insert ( def_id, vis) ;
1257+ self . r . feed_visibility ( def_id, vis) ;
12561258 self . parent_scope . macro_rules
12571259 }
12581260 }
@@ -1354,7 +1356,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
13541356 // Trait impl item visibility is inherited from its trait when not specified
13551357 // explicitly. In that case we cannot determine it here in early resolve,
13561358 // so we leave a hole in the visibility table to be filled later.
1357- self . r . visibilities . insert ( local_def_id, vis) ;
1359+ self . r . feed_visibility ( local_def_id, vis) ;
13581360 }
13591361
13601362 if ctxt == AssocCtxt :: Trait {
@@ -1432,7 +1434,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
14321434 self . visit_invoc ( sf. id ) ;
14331435 } else {
14341436 let vis = self . resolve_visibility ( & sf. vis ) ;
1435- self . r . visibilities . insert ( self . r . local_def_id ( sf. id ) , vis) ;
1437+ self . r . feed_visibility ( self . r . local_def_id ( sf. id ) , vis) ;
14361438 visit:: walk_field_def ( self , sf) ;
14371439 }
14381440 }
@@ -1453,7 +1455,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
14531455 let def_id = self . r . local_def_id ( variant. id ) ;
14541456 let vis = self . resolve_visibility ( & variant. vis ) ;
14551457 self . r . define ( parent, ident, TypeNS , ( self . res ( def_id) , vis, variant. span , expn_id) ) ;
1456- self . r . visibilities . insert ( def_id, vis) ;
1458+ self . r . feed_visibility ( def_id, vis) ;
14571459
14581460 // If the variant is marked as non_exhaustive then lower the visibility to within the crate.
14591461 let ctor_vis =
@@ -1468,7 +1470,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
14681470 let ctor_def_id = self . r . local_def_id ( ctor_node_id) ;
14691471 let ctor_res = self . res ( ctor_def_id) ;
14701472 self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, variant. span , expn_id) ) ;
1471- self . r . visibilities . insert ( ctor_def_id, ctor_vis) ;
1473+ self . r . feed_visibility ( ctor_def_id, ctor_vis) ;
14721474 }
14731475
14741476 // Record field names for error reporting.
0 commit comments