@@ -33,39 +33,42 @@ use crate::imports::{ImportData, ImportKind};
3333use crate :: macros:: { MacroRulesBinding , MacroRulesScope , MacroRulesScopeRef } ;
3434use crate :: {
3535 BindingKey , ExternPreludeEntry , Finalize , MacroData , Module , ModuleKind , ModuleOrUniformRoot ,
36- NameBinding , NameBindingData , NameBindingKind , ParentScope , PathResult , ResolutionError ,
37- Resolver , ResolverArenas , Segment , ToNameBinding , Used , VisResolutionError , errors,
36+ NameBinding , ParentScope , PathResult , ResolutionError , Resolver , Segment , Used ,
37+ VisResolutionError , errors,
3838} ;
3939
4040type Res = def:: Res < NodeId > ;
4141
42- impl < ' ra , Id : Into < DefId > > ToNameBinding < ' ra > for ( Res , ty:: Visibility < Id > , Span , LocalExpnId ) {
43- fn to_name_binding ( self , arenas : & ' ra ResolverArenas < ' ra > ) -> NameBinding < ' ra > {
44- arenas. alloc_name_binding ( NameBindingData {
45- kind : NameBindingKind :: Res ( self . 0 ) ,
46- ambiguity : None ,
47- warn_ambiguity : false ,
48- vis : self . 1 . to_def_id ( ) ,
49- span : self . 2 ,
50- expansion : self . 3 ,
51- } )
52- }
53- }
54-
5542impl < ' ra , ' tcx > Resolver < ' ra , ' tcx > {
5643 /// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
5744 /// otherwise, reports an error.
58- pub ( crate ) fn define < T > ( & mut self , parent : Module < ' ra > , ident : Ident , ns : Namespace , def : T )
59- where
60- T : ToNameBinding < ' ra > ,
61- {
62- let binding = def. to_name_binding ( self . arenas ) ;
45+ pub ( crate ) fn define_binding (
46+ & mut self ,
47+ parent : Module < ' ra > ,
48+ ident : Ident ,
49+ ns : Namespace ,
50+ binding : NameBinding < ' ra > ,
51+ ) {
6352 let key = self . new_disambiguated_key ( ident, ns) ;
6453 if let Err ( old_binding) = self . try_define ( parent, key, binding, false ) {
6554 self . report_conflict ( parent, ident, ns, old_binding, binding) ;
6655 }
6756 }
6857
58+ fn define (
59+ & mut self ,
60+ parent : Module < ' ra > ,
61+ ident : Ident ,
62+ ns : Namespace ,
63+ res : Res ,
64+ vis : ty:: Visibility < impl Into < DefId > > ,
65+ span : Span ,
66+ expn_id : LocalExpnId ,
67+ ) {
68+ let binding = self . arenas . new_res_binding ( res, vis. to_def_id ( ) , span, expn_id) ;
69+ self . define_binding ( parent, ident, ns, binding)
70+ }
71+
6972 /// Walks up the tree of definitions starting at `def_id`,
7073 /// stopping at the first encountered module.
7174 /// Parent block modules for arbitrary def-ids are not recorded for the local crate,
@@ -223,7 +226,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
223226 _,
224227 )
225228 | Res :: PrimTy ( ..)
226- | Res :: ToolMod => self . define ( parent, ident, TypeNS , ( res, vis, span, expansion) ) ,
229+ | Res :: ToolMod => self . define ( parent, ident, TypeNS , res, vis, span, expansion) ,
227230 Res :: Def (
228231 DefKind :: Fn
229232 | DefKind :: AssocFn
@@ -232,9 +235,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
232235 | DefKind :: AssocConst
233236 | DefKind :: Ctor ( ..) ,
234237 _,
235- ) => self . define ( parent, ident, ValueNS , ( res, vis, span, expansion) ) ,
238+ ) => self . define ( parent, ident, ValueNS , res, vis, span, expansion) ,
236239 Res :: Def ( DefKind :: Macro ( ..) , _) | Res :: NonMacroAttr ( ..) => {
237- self . define ( parent, ident, MacroNS , ( res, vis, span, expansion) )
240+ self . define ( parent, ident, MacroNS , res, vis, span, expansion)
238241 }
239242 Res :: Def (
240243 DefKind :: TyParam
@@ -698,7 +701,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
698701 let expansion = parent_scope. expansion ;
699702
700703 // Define a name in the type namespace if it is not anonymous.
701- self . r . define ( parent, ident, TypeNS , ( adt_res, adt_vis, adt_span, expansion) ) ;
704+ self . r . define ( parent, ident, TypeNS , adt_res, adt_vis, adt_span, expansion) ;
702705 self . r . feed_visibility ( feed, adt_vis) ;
703706 let def_id = feed. key ( ) ;
704707
@@ -750,7 +753,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
750753 }
751754
752755 ItemKind :: Mod ( _, ident, ref mod_kind) => {
753- self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
756+ self . r . define ( parent, ident, TypeNS , res, vis, sp, expansion) ;
754757
755758 if let ast:: ModKind :: Loaded ( _, _, _, Err ( _) ) = mod_kind {
756759 self . r . mods_with_parse_errors . insert ( def_id) ;
@@ -769,10 +772,10 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
769772 ItemKind :: Const ( box ConstItem { ident, .. } )
770773 | ItemKind :: Delegation ( box Delegation { ident, .. } )
771774 | ItemKind :: Static ( box StaticItem { ident, .. } ) => {
772- self . r . define ( parent, ident, ValueNS , ( res, vis, sp, expansion) ) ;
775+ self . r . define ( parent, ident, ValueNS , res, vis, sp, expansion) ;
773776 }
774777 ItemKind :: Fn ( box Fn { ident, .. } ) => {
775- self . r . define ( parent, ident, ValueNS , ( res, vis, sp, expansion) ) ;
778+ self . r . define ( parent, ident, ValueNS , res, vis, sp, expansion) ;
776779
777780 // Functions introducing procedural macros reserve a slot
778781 // in the macro namespace as well (see #52225).
@@ -781,11 +784,11 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
781784
782785 // These items live in the type namespace.
783786 ItemKind :: TyAlias ( box TyAlias { ident, .. } ) | ItemKind :: TraitAlias ( ident, ..) => {
784- self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
787+ self . r . define ( parent, ident, TypeNS , res, vis, sp, expansion) ;
785788 }
786789
787790 ItemKind :: Enum ( ident, _, _) | ItemKind :: Trait ( box ast:: Trait { ident, .. } ) => {
788- self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
791+ self . r . define ( parent, ident, TypeNS , res, vis, sp, expansion) ;
789792
790793 self . parent_scope . module = self . r . new_module (
791794 Some ( parent) ,
@@ -837,7 +840,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
837840 let feed = self . r . feed ( ctor_node_id) ;
838841 let ctor_def_id = feed. key ( ) ;
839842 let ctor_res = self . res ( ctor_def_id) ;
840- self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, sp, expansion) ) ;
843+ self . r . define ( parent, ident, ValueNS , ctor_res, ctor_vis, sp, expansion) ;
841844 self . r . feed_visibility ( feed, ctor_vis) ;
842845 // We need the field visibility spans also for the constructor for E0603.
843846 self . insert_field_visibilities_local ( ctor_def_id. to_def_id ( ) , vdata. fields ( ) ) ;
@@ -901,9 +904,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
901904 }
902905 . map ( |module| {
903906 let used = self . process_macro_use_imports ( item, module) ;
904- let res = module. res ( ) . unwrap ( ) ;
905- let vis = ty:: Visibility :: < LocalDefId > :: Public ;
906- let binding = ( res, vis, sp, expansion) . to_name_binding ( self . r . arenas ) ;
907+ let binding = self . r . arenas . new_pub_res_binding ( module. res ( ) . unwrap ( ) , sp, expansion) ;
907908 ( used, Some ( ModuleOrUniformRoot :: Module ( module) ) , binding)
908909 } )
909910 . unwrap_or ( ( true , None , self . r . dummy_binding ) ) ;
@@ -960,7 +961,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
960961 ) ;
961962 }
962963 }
963- self . r . define ( parent, ident, TypeNS , imported_binding) ;
964+ self . r . define_binding ( parent, ident, TypeNS , imported_binding) ;
964965 }
965966
966967 /// Constructs the reduced graph for one foreign item.
@@ -977,7 +978,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
977978 let parent = self . parent_scope . module ;
978979 let expansion = self . parent_scope . expansion ;
979980 let vis = self . resolve_visibility ( & item. vis ) ;
980- self . r . define ( parent, ident, ns, ( self . res ( def_id) , vis, item. span , expansion) ) ;
981+ self . r . define ( parent, ident, ns, self . res ( def_id) , vis, item. span , expansion) ;
981982 self . r . feed_visibility ( feed, vis) ;
982983 }
983984
@@ -1217,7 +1218,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
12171218 } else {
12181219 ty:: Visibility :: Restricted ( CRATE_DEF_ID )
12191220 } ;
1220- let binding = ( res, vis, span, expansion) . to_name_binding ( self . r . arenas ) ;
1221+ let binding = self . r . arenas . new_res_binding ( res, vis. to_def_id ( ) , span, expansion) ;
12211222 self . r . set_binding_parent_module ( binding, parent_scope. module ) ;
12221223 self . r . all_macro_rules . insert ( ident. name ) ;
12231224 if is_macro_export {
@@ -1236,7 +1237,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
12361237 } ) ;
12371238 self . r . import_use_map . insert ( import, Used :: Other ) ;
12381239 let import_binding = self . r . import ( binding, import) ;
1239- self . r . define ( self . r . graph_root , ident, MacroNS , import_binding) ;
1240+ self . r . define_binding ( self . r . graph_root , ident, MacroNS , import_binding) ;
12401241 } else {
12411242 self . r . check_reserved_macro_name ( ident, res) ;
12421243 self . insert_unused_macro ( ident, def_id, item. id ) ;
@@ -1264,7 +1265,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
12641265 if !vis. is_public ( ) {
12651266 self . insert_unused_macro ( ident, def_id, item. id ) ;
12661267 }
1267- self . r . define ( module, ident, MacroNS , ( res, vis, span, expansion) ) ;
1268+ self . r . define ( module, ident, MacroNS , res, vis, span, expansion) ;
12681269 self . r . feed_visibility ( feed, vis) ;
12691270 self . parent_scope . macro_rules
12701271 }
@@ -1400,7 +1401,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
14001401 if ctxt == AssocCtxt :: Trait {
14011402 let parent = self . parent_scope . module ;
14021403 let expansion = self . parent_scope . expansion ;
1403- self . r . define ( parent, ident, ns, ( self . res ( def_id) , vis, item. span , expansion) ) ;
1404+ self . r . define ( parent, ident, ns, self . res ( def_id) , vis, item. span , expansion) ;
14041405 } else if !matches ! ( & item. kind, AssocItemKind :: Delegation ( deleg) if deleg. from_glob) {
14051406 let impl_def_id = self . r . tcx . local_parent ( local_def_id) ;
14061407 let key = BindingKey :: new ( ident. normalize_to_macros_2_0 ( ) , ns) ;
@@ -1485,7 +1486,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
14851486 let feed = self . r . feed ( variant. id ) ;
14861487 let def_id = feed. key ( ) ;
14871488 let vis = self . resolve_visibility ( & variant. vis ) ;
1488- self . r . define ( parent, ident, TypeNS , ( self . res ( def_id) , vis, variant. span , expn_id) ) ;
1489+ self . r . define ( parent, ident, TypeNS , self . res ( def_id) , vis, variant. span , expn_id) ;
14891490 self . r . feed_visibility ( feed, vis) ;
14901491
14911492 // If the variant is marked as non_exhaustive then lower the visibility to within the crate.
@@ -1501,7 +1502,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
15011502 let feed = self . r . feed ( ctor_node_id) ;
15021503 let ctor_def_id = feed. key ( ) ;
15031504 let ctor_res = self . res ( ctor_def_id) ;
1504- self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, variant. span , expn_id) ) ;
1505+ self . r . define ( parent, ident, ValueNS , ctor_res, ctor_vis, variant. span , expn_id) ;
15051506 self . r . feed_visibility ( feed, ctor_vis) ;
15061507 }
15071508
0 commit comments