@@ -25,6 +25,7 @@ use rustc_hir::def::{self, *};
2525use rustc_hir:: def_id:: { DefId , LocalDefId , CRATE_DEF_ID } ;
2626use rustc_metadata:: creader:: LoadedMacro ;
2727use rustc_middle:: metadata:: ModChild ;
28+ use rustc_middle:: ty:: Feed ;
2829use rustc_middle:: { bug, ty} ;
2930use rustc_span:: hygiene:: { ExpnId , LocalExpnId , MacroKind } ;
3031use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
@@ -407,7 +408,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
407408 // Top level use tree reuses the item's id and list stems reuse their parent
408409 // use tree's ids, so in both cases their visibilities are already filled.
409410 if nested && !list_stem {
410- self . r . feed_visibility ( self . r . local_def_id ( id) , vis) ;
411+ self . r . feed_visibility ( self . r . feed ( id) , vis) ;
411412 }
412413
413414 let mut prefix_iter = parent_prefix
@@ -632,7 +633,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
632633 & mut self ,
633634 fields : & [ ast:: FieldDef ] ,
634635 ident : Ident ,
635- def_id : LocalDefId ,
636+ feed : Feed < ' tcx , LocalDefId > ,
636637 adt_res : Res ,
637638 adt_vis : ty:: Visibility ,
638639 adt_span : Span ,
@@ -643,7 +644,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
643644
644645 // Define a name in the type namespace if it is not anonymous.
645646 self . r . define ( parent, ident, TypeNS , ( adt_res, adt_vis, adt_span, expansion) ) ;
646- self . r . feed_visibility ( def_id, adt_vis) ;
647+ self . r . feed_visibility ( feed, adt_vis) ;
648+ let def_id = feed. key ( ) ;
647649
648650 // Record field names for error reporting.
649651 self . insert_field_def_ids ( def_id, fields) ;
@@ -653,14 +655,15 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
653655 match & field. ty . kind {
654656 ast:: TyKind :: AnonStruct ( id, nested_fields)
655657 | ast:: TyKind :: AnonUnion ( id, nested_fields) => {
656- let local_def_id = self . r . local_def_id ( * id) ;
658+ let feed = self . r . feed ( * id) ;
659+ let local_def_id = feed. key ( ) ;
657660 let def_id = local_def_id. to_def_id ( ) ;
658661 let def_kind = self . r . tcx . def_kind ( local_def_id) ;
659662 let res = Res :: Def ( def_kind, def_id) ;
660663 self . build_reduced_graph_for_struct_variant (
661664 & nested_fields,
662665 Ident :: empty ( ) ,
663- local_def_id ,
666+ feed ,
664667 res,
665668 // Anonymous adts inherit visibility from their parent adts.
666669 adt_vis,
@@ -680,12 +683,13 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
680683 let ident = item. ident ;
681684 let sp = item. span ;
682685 let vis = self . resolve_visibility ( & item. vis ) ;
683- let local_def_id = self . r . local_def_id ( item. id ) ;
686+ let feed = self . r . feed ( item. id ) ;
687+ let local_def_id = feed. key ( ) ;
684688 let def_id = local_def_id. to_def_id ( ) ;
685689 let def_kind = self . r . tcx . def_kind ( def_id) ;
686690 let res = Res :: Def ( def_kind, def_id) ;
687691
688- self . r . feed_visibility ( local_def_id , vis) ;
692+ self . r . feed_visibility ( feed , vis) ;
689693
690694 match item. kind {
691695 ItemKind :: Use ( ref use_tree) => {
@@ -762,7 +766,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
762766 self . build_reduced_graph_for_struct_variant (
763767 vdata. fields ( ) ,
764768 ident,
765- local_def_id ,
769+ feed ,
766770 res,
767771 vis,
768772 sp,
@@ -795,10 +799,11 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
795799 }
796800 ret_fields. push ( field_vis. to_def_id ( ) ) ;
797801 }
798- let ctor_def_id = self . r . local_def_id ( ctor_node_id) ;
802+ let feed = self . r . feed ( ctor_node_id) ;
803+ let ctor_def_id = feed. key ( ) ;
799804 let ctor_res = self . res ( ctor_def_id) ;
800805 self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, sp, expansion) ) ;
801- self . r . feed_visibility ( ctor_def_id , ctor_vis) ;
806+ self . r . feed_visibility ( feed , ctor_vis) ;
802807 // We need the field visibility spans also for the constructor for E0603.
803808 self . insert_field_visibilities_local ( ctor_def_id. to_def_id ( ) , vdata. fields ( ) ) ;
804809
@@ -812,7 +817,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
812817 self . build_reduced_graph_for_struct_variant (
813818 vdata. fields ( ) ,
814819 ident,
815- local_def_id ,
820+ feed ,
816821 res,
817822 vis,
818823 sp,
@@ -919,7 +924,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
919924
920925 /// Constructs the reduced graph for one foreign item.
921926 fn build_reduced_graph_for_foreign_item ( & mut self , item : & ForeignItem ) {
922- let local_def_id = self . r . local_def_id ( item. id ) ;
927+ let feed = self . r . feed ( item. id ) ;
928+ let local_def_id = feed. key ( ) ;
923929 let def_id = local_def_id. to_def_id ( ) ;
924930 let ns = match item. kind {
925931 ForeignItemKind :: Fn ( ..) => ValueNS ,
@@ -931,7 +937,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
931937 let expansion = self . parent_scope . expansion ;
932938 let vis = self . resolve_visibility ( & item. vis ) ;
933939 self . r . define ( parent, item. ident , ns, ( self . res ( def_id) , vis, item. span , expansion) ) ;
934- self . r . feed_visibility ( local_def_id , vis) ;
940+ self . r . feed_visibility ( feed , vis) ;
935941 }
936942
937943 fn build_reduced_graph_for_block ( & mut self , block : & Block ) {
@@ -1218,7 +1224,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
12181224 fn define_macro ( & mut self , item : & ast:: Item ) -> MacroRulesScopeRef < ' a > {
12191225 let parent_scope = self . parent_scope ;
12201226 let expansion = parent_scope. expansion ;
1221- let def_id = self . r . local_def_id ( item. id ) ;
1227+ let feed = self . r . feed ( item. id ) ;
1228+ let def_id = feed. key ( ) ;
12221229 let ( res, ident, span, macro_rules) = match & item. kind {
12231230 ItemKind :: MacroDef ( def) => ( self . res ( def_id) , item. ident , item. span , def. macro_rules ) ,
12241231 ItemKind :: Fn ( ..) => match self . proc_macro_stub ( item) {
@@ -1269,7 +1276,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
12691276 self . r . check_reserved_macro_name ( ident, res) ;
12701277 self . insert_unused_macro ( ident, def_id, item. id ) ;
12711278 }
1272- self . r . feed_visibility ( def_id , vis) ;
1279+ self . r . feed_visibility ( feed , vis) ;
12731280 let scope = self . r . arenas . alloc_macro_rules_scope ( MacroRulesScope :: Binding (
12741281 self . r . arenas . alloc_macro_rules_binding ( MacroRulesBinding {
12751282 parent_macro_rules_scope : parent_scope. macro_rules ,
@@ -1293,7 +1300,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
12931300 self . insert_unused_macro ( ident, def_id, item. id ) ;
12941301 }
12951302 self . r . define ( module, ident, MacroNS , ( res, vis, span, expansion) ) ;
1296- self . r . feed_visibility ( def_id , vis) ;
1303+ self . r . feed_visibility ( feed , vis) ;
12971304 self . parent_scope . macro_rules
12981305 }
12991306 }
@@ -1385,7 +1392,8 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
13851392 }
13861393
13871394 let vis = self . resolve_visibility ( & item. vis ) ;
1388- let local_def_id = self . r . local_def_id ( item. id ) ;
1395+ let feed = self . r . feed ( item. id ) ;
1396+ let local_def_id = feed. key ( ) ;
13891397 let def_id = local_def_id. to_def_id ( ) ;
13901398
13911399 if !( ctxt == AssocCtxt :: Impl
@@ -1395,7 +1403,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
13951403 // Trait impl item visibility is inherited from its trait when not specified
13961404 // explicitly. In that case we cannot determine it here in early resolve,
13971405 // so we leave a hole in the visibility table to be filled later.
1398- self . r . feed_visibility ( local_def_id , vis) ;
1406+ self . r . feed_visibility ( feed , vis) ;
13991407 }
14001408
14011409 if ctxt == AssocCtxt :: Trait {
@@ -1469,7 +1477,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
14691477 self . visit_invoc ( sf. id ) ;
14701478 } else {
14711479 let vis = self . resolve_visibility ( & sf. vis ) ;
1472- self . r . feed_visibility ( self . r . local_def_id ( sf. id ) , vis) ;
1480+ self . r . feed_visibility ( self . r . feed ( sf. id ) , vis) ;
14731481 visit:: walk_field_def ( self , sf) ;
14741482 }
14751483 }
@@ -1487,10 +1495,11 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
14871495 let ident = variant. ident ;
14881496
14891497 // Define a name in the type namespace.
1490- let def_id = self . r . local_def_id ( variant. id ) ;
1498+ let feed = self . r . feed ( variant. id ) ;
1499+ let def_id = feed. key ( ) ;
14911500 let vis = self . resolve_visibility ( & variant. vis ) ;
14921501 self . r . define ( parent, ident, TypeNS , ( self . res ( def_id) , vis, variant. span , expn_id) ) ;
1493- self . r . feed_visibility ( def_id , vis) ;
1502+ self . r . feed_visibility ( feed , vis) ;
14941503
14951504 // If the variant is marked as non_exhaustive then lower the visibility to within the crate.
14961505 let ctor_vis =
@@ -1502,10 +1511,11 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
15021511
15031512 // Define a constructor name in the value namespace.
15041513 if let Some ( ctor_node_id) = variant. data . ctor_node_id ( ) {
1505- let ctor_def_id = self . r . local_def_id ( ctor_node_id) ;
1514+ let feed = self . r . feed ( ctor_node_id) ;
1515+ let ctor_def_id = feed. key ( ) ;
15061516 let ctor_res = self . res ( ctor_def_id) ;
15071517 self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, variant. span , expn_id) ) ;
1508- self . r . feed_visibility ( ctor_def_id , ctor_vis) ;
1518+ self . r . feed_visibility ( feed , ctor_vis) ;
15091519 }
15101520
15111521 // Record field names for error reporting.
0 commit comments