@@ -33,31 +33,33 @@ use tracing::debug;
3333use crate :: Namespace :: { MacroNS , TypeNS , ValueNS } ;
3434use crate :: def_collector:: collect_definitions;
3535use crate :: imports:: { ImportData , ImportKind } ;
36- use crate :: macros:: { MacroRulesBinding , MacroRulesScope , MacroRulesScopeRef } ;
36+ use crate :: macros:: { MacroRulesDecl , MacroRulesScope , MacroRulesScopeRef } ;
3737use crate :: ref_mut:: CmCell ;
3838use crate :: {
39- BindingKey , ExternPreludeEntry , Finalize , MacroData , Module , ModuleKind , ModuleOrUniformRoot ,
40- NameBinding , NameBindingData , NameBindingKind , ParentScope , PathResult , ResolutionError ,
41- Resolver , Segment , Used , VisResolutionError , errors,
39+ BindingKey , Decl , DeclData , DeclKind , ExternPreludeEntry , Finalize , MacroData , Module ,
40+ ModuleKind , ModuleOrUniformRoot , ParentScope , PathResult , ResolutionError , Resolver , Segment ,
41+ Used , VisResolutionError , errors,
4242} ;
4343
4444type Res = def:: Res < NodeId > ;
4545
4646impl < ' ra , ' tcx > Resolver < ' ra , ' tcx > {
47- /// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
48- /// otherwise, reports an error.
49- pub ( crate ) fn define_binding_local (
47+ /// Attempt to put the declaration with the given name and namespace into the module,
48+ /// and report an error in case of a collision .
49+ pub ( crate ) fn plant_decl_into_local_module (
5050 & mut self ,
5151 parent : Module < ' ra > ,
5252 ident : Ident ,
5353 ns : Namespace ,
54- binding : NameBinding < ' ra > ,
54+ decl : Decl < ' ra > ,
5555 ) {
56- if let Err ( old_binding) = self . try_define_local ( parent, ident, ns, binding, false ) {
57- self . report_conflict ( parent, ident, ns, old_binding, binding) ;
56+ if let Err ( old_decl) = self . try_plant_decl_into_local_module ( parent, ident, ns, decl, false )
57+ {
58+ self . report_conflict ( parent, ident, ns, old_decl, decl) ;
5859 }
5960 }
6061
62+ /// Create a name definitinon from the given components, and put it into the local module.
6163 fn define_local (
6264 & mut self ,
6365 parent : Module < ' ra > ,
@@ -68,10 +70,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
6870 span : Span ,
6971 expn_id : LocalExpnId ,
7072 ) {
71- let binding = self . arenas . new_res_binding ( res, vis. to_def_id ( ) , span, expn_id) ;
72- self . define_binding_local ( parent, ident, ns, binding ) ;
73+ let decl = self . arenas . new_def_decl ( res, vis. to_def_id ( ) , span, expn_id) ;
74+ self . plant_decl_into_local_module ( parent, ident, ns, decl ) ;
7375 }
7476
77+ /// Create a name definitinon from the given components, and put it into the extern module.
7578 fn define_extern (
7679 & self ,
7780 parent : Module < ' ra > ,
@@ -82,10 +85,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
8285 vis : Visibility < DefId > ,
8386 span : Span ,
8487 expansion : LocalExpnId ,
85- ambiguity : Option < NameBinding < ' ra > > ,
88+ ambiguity : Option < Decl < ' ra > > ,
8689 ) {
87- let binding = self . arenas . alloc_name_binding ( NameBindingData {
88- kind : NameBindingKind :: Res ( res) ,
90+ let decl = self . arenas . alloc_decl ( DeclData {
91+ kind : DeclKind :: Def ( res) ,
8992 ambiguity,
9093 // External ambiguities always report the `AMBIGUOUS_GLOB_IMPORTS` lint at the moment.
9194 warn_ambiguity : true ,
@@ -101,8 +104,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
101104 if self
102105 . resolution_or_default ( parent, key)
103106 . borrow_mut_unchecked ( )
104- . non_glob_binding
105- . replace ( binding )
107+ . non_glob_decl
108+ . replace ( decl )
106109 . is_some ( )
107110 {
108111 span_bug ! ( span, "an external binding was already defined" ) ;
@@ -284,7 +287,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
284287 let ModChild { ident : _, res, vis, ref reexport_chain } = * ambig_child;
285288 let span = child_span ( self , reexport_chain, res) ;
286289 let res = res. expect_non_local ( ) ;
287- self . arenas . new_res_binding ( res, vis, span, expansion)
290+ self . arenas . new_def_decl ( res, vis, span, expansion)
288291 } ) ;
289292
290293 // Record primary definitions.
@@ -691,7 +694,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
691694 let kind = ImportKind :: Single {
692695 source : source. ident ,
693696 target : ident,
694- bindings : Default :: default ( ) ,
697+ decls : Default :: default ( ) ,
695698 type_ns_only,
696699 nested,
697700 id,
@@ -977,7 +980,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
977980 let parent_scope = self . parent_scope ;
978981 let expansion = parent_scope. expansion ;
979982
980- let ( used, module, binding ) = if orig_name. is_none ( ) && ident. name == kw:: SelfLower {
983+ let ( used, module, decl ) = if orig_name. is_none ( ) && ident. name == kw:: SelfLower {
981984 self . r . dcx ( ) . emit_err ( errors:: ExternCrateSelfRequiresRenaming { span : sp } ) ;
982985 return ;
983986 } else if orig_name == Some ( kw:: SelfLower ) {
@@ -997,10 +1000,10 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
9971000 }
9981001 . map ( |module| {
9991002 let used = self . process_macro_use_imports ( item, module) ;
1000- let binding = self . r . arenas . new_pub_res_binding ( module. res ( ) . unwrap ( ) , sp, expansion) ;
1001- ( used, Some ( ModuleOrUniformRoot :: Module ( module) ) , binding )
1003+ let decl = self . r . arenas . new_pub_def_decl ( module. res ( ) . unwrap ( ) , sp, expansion) ;
1004+ ( used, Some ( ModuleOrUniformRoot :: Module ( module) ) , decl )
10021005 } )
1003- . unwrap_or ( ( true , None , self . r . dummy_binding ) ) ;
1006+ . unwrap_or ( ( true , None , self . r . dummy_decl ) ) ;
10041007 let import = self . r . arenas . alloc_import ( ImportData {
10051008 kind : ImportKind :: ExternCrate { source : orig_name, target : ident, id : item. id } ,
10061009 root_id : item. id ,
@@ -1019,15 +1022,15 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
10191022 self . r . import_use_map . insert ( import, Used :: Other ) ;
10201023 }
10211024 self . r . potentially_unused_imports . push ( import) ;
1022- let imported_binding = self . r . import ( binding , import) ;
1025+ let import_decl = self . r . new_import_decl ( decl , import) ;
10231026 if ident. name != kw:: Underscore && parent == self . r . graph_root {
10241027 let norm_ident = Macros20NormalizedIdent :: new ( ident) ;
10251028 // FIXME: this error is technically unnecessary now when extern prelude is split into
10261029 // two scopes, remove it with lang team approval.
10271030 if let Some ( entry) = self . r . extern_prelude . get ( & norm_ident)
10281031 && expansion != LocalExpnId :: ROOT
10291032 && orig_name. is_some ( )
1030- && entry. item_binding . is_none ( )
1033+ && entry. item_decl . is_none ( )
10311034 {
10321035 self . r . dcx ( ) . emit_err (
10331036 errors:: MacroExpandedExternCrateCannotShadowExternArguments { span : item. span } ,
@@ -1038,21 +1041,21 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
10381041 match self . r . extern_prelude . entry ( norm_ident) {
10391042 Entry :: Occupied ( mut occupied) => {
10401043 let entry = occupied. get_mut ( ) ;
1041- if entry. item_binding . is_some ( ) {
1044+ if entry. item_decl . is_some ( ) {
10421045 let msg = format ! ( "extern crate `{ident}` already in extern prelude" ) ;
10431046 self . r . tcx . dcx ( ) . span_delayed_bug ( item. span , msg) ;
10441047 } else {
1045- entry. item_binding = Some ( ( imported_binding , orig_name. is_some ( ) ) ) ;
1048+ entry. item_decl = Some ( ( import_decl , orig_name. is_some ( ) ) ) ;
10461049 }
10471050 entry
10481051 }
10491052 Entry :: Vacant ( vacant) => vacant. insert ( ExternPreludeEntry {
1050- item_binding : Some ( ( imported_binding , true ) ) ,
1051- flag_binding : None ,
1053+ item_decl : Some ( ( import_decl , true ) ) ,
1054+ flag_decl : None ,
10521055 } ) ,
10531056 } ;
10541057 }
1055- self . r . define_binding_local ( parent, ident, TypeNS , imported_binding ) ;
1058+ self . r . plant_decl_into_local_module ( parent, ident, TypeNS , import_decl ) ;
10561059 }
10571060
10581061 /// Constructs the reduced graph for one foreign item.
@@ -1089,14 +1092,14 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
10891092 }
10901093 }
10911094
1092- fn add_macro_use_binding (
1095+ fn add_macro_use_decl (
10931096 & mut self ,
10941097 name : Symbol ,
1095- binding : NameBinding < ' ra > ,
1098+ decl : Decl < ' ra > ,
10961099 span : Span ,
10971100 allow_shadowing : bool ,
10981101 ) {
1099- if self . r . macro_use_prelude . insert ( name, binding ) . is_some ( ) && !allow_shadowing {
1102+ if self . r . macro_use_prelude . insert ( name, decl ) . is_some ( ) && !allow_shadowing {
11001103 self . r . dcx ( ) . emit_err ( errors:: MacroUseNameAlreadyInUse { span, name } ) ;
11011104 }
11021105 }
@@ -1167,8 +1170,8 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
11671170 }
11681171 macro_use_import ( this, span, true )
11691172 } ;
1170- let import_binding = this. r . import ( binding, import) ;
1171- this. add_macro_use_binding ( ident. name , import_binding , span, allow_shadowing) ;
1173+ let import_decl = this. r . new_import_decl ( binding, import) ;
1174+ this. add_macro_use_decl ( ident. name , import_decl , span, allow_shadowing) ;
11721175 }
11731176 } ) ;
11741177 } else {
@@ -1183,13 +1186,8 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
11831186 if let Ok ( binding) = result {
11841187 let import = macro_use_import ( self , ident. span , false ) ;
11851188 self . r . potentially_unused_imports . push ( import) ;
1186- let imported_binding = self . r . import ( binding, import) ;
1187- self . add_macro_use_binding (
1188- ident. name ,
1189- imported_binding,
1190- ident. span ,
1191- allow_shadowing,
1192- ) ;
1189+ let import_decl = self . r . new_import_decl ( binding, import) ;
1190+ self . add_macro_use_decl ( ident. name , import_decl, ident. span , allow_shadowing) ;
11931191 } else {
11941192 self . r . dcx ( ) . emit_err ( errors:: ImportedMacroNotFound { span : ident. span } ) ;
11951193 }
@@ -1300,8 +1298,8 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
13001298 } else {
13011299 Visibility :: Restricted ( CRATE_DEF_ID )
13021300 } ;
1303- let binding = self . r . arenas . new_res_binding ( res, vis. to_def_id ( ) , span, expansion) ;
1304- self . r . set_binding_parent_module ( binding , parent_scope. module ) ;
1301+ let decl = self . r . arenas . new_def_decl ( res, vis. to_def_id ( ) , span, expansion) ;
1302+ self . r . set_decl_parent_module ( decl , parent_scope. module ) ;
13051303 self . r . all_macro_rules . insert ( ident. name ) ;
13061304 if is_macro_export {
13071305 let import = self . r . arenas . alloc_import ( ImportData {
@@ -1319,17 +1317,17 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
13191317 vis_span : item. vis . span ,
13201318 } ) ;
13211319 self . r . import_use_map . insert ( import, Used :: Other ) ;
1322- let import_binding = self . r . import ( binding , import) ;
1323- self . r . define_binding_local ( self . r . graph_root , ident, MacroNS , import_binding ) ;
1320+ let import_decl = self . r . new_import_decl ( decl , import) ;
1321+ self . r . plant_decl_into_local_module ( self . r . graph_root , ident, MacroNS , import_decl ) ;
13241322 } else {
13251323 self . r . check_reserved_macro_name ( ident, res) ;
13261324 self . insert_unused_macro ( ident, def_id, item. id ) ;
13271325 }
13281326 self . r . feed_visibility ( feed, vis) ;
1329- let scope = self . r . arenas . alloc_macro_rules_scope ( MacroRulesScope :: Binding (
1330- self . r . arenas . alloc_macro_rules_binding ( MacroRulesBinding {
1327+ let scope = self . r . arenas . alloc_macro_rules_scope ( MacroRulesScope :: Def (
1328+ self . r . arenas . alloc_macro_rules_decl ( MacroRulesDecl {
13311329 parent_macro_rules_scope : parent_scope. macro_rules ,
1332- binding ,
1330+ decl ,
13331331 ident,
13341332 } ) ,
13351333 ) ) ;
0 commit comments