@@ -236,7 +236,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
236
236
// (i.e. variants, fields, and trait items) inherits from the visibility
237
237
// of the enum or trait.
238
238
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 ( )
240
240
}
241
241
// Otherwise, the visibility is restricted to the nearest parent `mod` item.
242
242
_ => ty:: Visibility :: Restricted (
@@ -404,6 +404,10 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
404
404
parent_prefix, use_tree, nested
405
405
) ;
406
406
407
+ if nested {
408
+ self . r . feed_visibility ( self . r . local_def_id ( id) , vis) ;
409
+ }
410
+
407
411
let mut prefix_iter = parent_prefix
408
412
. iter ( )
409
413
. cloned ( )
@@ -442,8 +446,6 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
442
446
let mut source = module_path. pop ( ) . unwrap ( ) ;
443
447
let mut type_ns_only = false ;
444
448
445
- self . r . visibilities . insert ( self . r . local_def_id ( id) , vis) ;
446
-
447
449
if nested {
448
450
// Correctly handle `self`
449
451
if source. ident . name == kw:: SelfLower {
@@ -557,7 +559,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
557
559
max_vis : Cell :: new ( None ) ,
558
560
id,
559
561
} ;
560
- self . r . visibilities . insert ( self . r . local_def_id ( id ) , vis ) ;
562
+
561
563
self . add_import ( prefix, kind, use_tree. span , item, root_span, item. id , vis) ;
562
564
}
563
565
ast:: UseTreeKind :: Nested ( ref items) => {
@@ -636,7 +638,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
636
638
let def_kind = self . r . tcx . def_kind ( def_id) ;
637
639
let res = Res :: Def ( def_kind, def_id) ;
638
640
639
- self . r . visibilities . insert ( local_def_id, vis) ;
641
+ self . r . feed_visibility ( local_def_id, vis) ;
640
642
641
643
match item. kind {
642
644
ItemKind :: Use ( ref use_tree) => {
@@ -753,7 +755,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
753
755
let ctor_def_id = self . r . local_def_id ( ctor_node_id) ;
754
756
let ctor_res = self . res ( ctor_def_id) ;
755
757
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) ;
757
759
// We need the field visibility spans also for the constructor for E0603.
758
760
self . insert_field_visibilities_local ( ctor_def_id. to_def_id ( ) , vdata) ;
759
761
@@ -897,7 +899,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
897
899
let expansion = self . parent_scope . expansion ;
898
900
let vis = self . resolve_visibility ( & item. vis ) ;
899
901
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) ;
901
903
}
902
904
903
905
fn build_reduced_graph_for_block ( & mut self , block : & Block ) {
@@ -1228,7 +1230,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1228
1230
self . r . check_reserved_macro_name ( ident, res) ;
1229
1231
self . insert_unused_macro ( ident, def_id, item. id ) ;
1230
1232
}
1231
- self . r . visibilities . insert ( def_id, vis) ;
1233
+ self . r . feed_visibility ( def_id, vis) ;
1232
1234
let scope = self . r . arenas . alloc_macro_rules_scope ( MacroRulesScope :: Binding (
1233
1235
self . r . arenas . alloc_macro_rules_binding ( MacroRulesBinding {
1234
1236
parent_macro_rules_scope : parent_scope. macro_rules ,
@@ -1252,7 +1254,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1252
1254
self . insert_unused_macro ( ident, def_id, item. id ) ;
1253
1255
}
1254
1256
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) ;
1256
1258
self . parent_scope . macro_rules
1257
1259
}
1258
1260
}
@@ -1354,7 +1356,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1354
1356
// Trait impl item visibility is inherited from its trait when not specified
1355
1357
// explicitly. In that case we cannot determine it here in early resolve,
1356
1358
// 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) ;
1358
1360
}
1359
1361
1360
1362
if ctxt == AssocCtxt :: Trait {
@@ -1432,7 +1434,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1432
1434
self . visit_invoc ( sf. id ) ;
1433
1435
} else {
1434
1436
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) ;
1436
1438
visit:: walk_field_def ( self , sf) ;
1437
1439
}
1438
1440
}
@@ -1453,7 +1455,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1453
1455
let def_id = self . r . local_def_id ( variant. id ) ;
1454
1456
let vis = self . resolve_visibility ( & variant. vis ) ;
1455
1457
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) ;
1457
1459
1458
1460
// If the variant is marked as non_exhaustive then lower the visibility to within the crate.
1459
1461
let ctor_vis =
@@ -1468,7 +1470,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1468
1470
let ctor_def_id = self . r . local_def_id ( ctor_node_id) ;
1469
1471
let ctor_res = self . res ( ctor_def_id) ;
1470
1472
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) ;
1472
1474
}
1473
1475
1474
1476
// Record field names for error reporting.
0 commit comments