@@ -26,7 +26,7 @@ use rustc_middle::metadata::{ModChild, Reexport};
2626use rustc_middle:: ty:: { Feed , Visibility } ;
2727use rustc_middle:: { bug, span_bug} ;
2828use rustc_span:: hygiene:: { ExpnId , LocalExpnId , MacroKind } ;
29- use rustc_span:: { Ident , Macros20NormalizedIdent , Span , Symbol , kw, sym} ;
29+ use rustc_span:: { Ident , Span , Symbol , kw, sym} ;
3030use thin_vec:: ThinVec ;
3131use tracing:: debug;
3232
@@ -36,9 +36,9 @@ use crate::imports::{ImportData, ImportKind};
3636use crate :: macros:: { MacroRulesDecl , MacroRulesScope , MacroRulesScopeRef } ;
3737use crate :: ref_mut:: CmCell ;
3838use crate :: {
39- BindingKey , Decl , DeclData , DeclKind , ExternPreludeEntry , Finalize , MacroData , Module ,
40- ModuleKind , ModuleOrUniformRoot , ParentScope , PathResult , ResolutionError , Resolver , Segment ,
41- Used , VisResolutionError , errors,
39+ BindingKey , Decl , DeclData , DeclKind , ExternPreludeEntry , Finalize , IdentKey , MacroData ,
40+ Module , ModuleKind , ModuleOrUniformRoot , ParentScope , PathResult , ResolutionError , Resolver ,
41+ Segment , Used , VisResolutionError , errors,
4242} ;
4343
4444type Res = def:: Res < NodeId > ;
@@ -48,36 +48,40 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
4848 /// and report an error in case of a collision.
4949 pub ( crate ) fn plant_decl_into_local_module (
5050 & mut self ,
51- ident : Macros20NormalizedIdent ,
51+ ident : IdentKey ,
52+ orig_ident_span : Span ,
5253 ns : Namespace ,
5354 decl : Decl < ' ra > ,
5455 ) {
55- if let Err ( old_decl) = self . try_plant_decl_into_local_module ( ident, ns, decl, false ) {
56- self . report_conflict ( ident. 0 , ns, old_decl, decl) ;
56+ if let Err ( old_decl) =
57+ self . try_plant_decl_into_local_module ( ident, orig_ident_span, ns, decl, false )
58+ {
59+ self . report_conflict ( ident, ns, old_decl, decl) ;
5760 }
5861 }
5962
6063 /// Create a name definitinon from the given components, and put it into the local module.
6164 fn define_local (
6265 & mut self ,
6366 parent : Module < ' ra > ,
64- ident : Ident ,
67+ orig_ident : Ident ,
6568 ns : Namespace ,
6669 res : Res ,
6770 vis : Visibility ,
6871 span : Span ,
6972 expn_id : LocalExpnId ,
7073 ) {
7174 let decl = self . arenas . new_def_decl ( res, vis. to_def_id ( ) , span, expn_id, Some ( parent) ) ;
72- let ident = Macros20NormalizedIdent :: new ( ident ) ;
73- self . plant_decl_into_local_module ( ident, ns, decl) ;
75+ let ident = IdentKey :: new ( orig_ident ) ;
76+ self . plant_decl_into_local_module ( ident, orig_ident . span , ns, decl) ;
7477 }
7578
7679 /// Create a name definitinon from the given components, and put it into the extern module.
7780 fn define_extern (
7881 & self ,
7982 parent : Module < ' ra > ,
80- ident : Macros20NormalizedIdent ,
83+ ident : IdentKey ,
84+ orig_ident_span : Span ,
8185 ns : Namespace ,
8286 child_index : usize ,
8387 res : Res ,
@@ -102,7 +106,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
102106 let key =
103107 BindingKey :: new_disambiguated ( ident, ns, || ( child_index + 1 ) . try_into ( ) . unwrap ( ) ) ; // 0 indicates no underscore
104108 if self
105- . resolution_or_default ( parent, key)
109+ . resolution_or_default ( parent, key, orig_ident_span )
106110 . borrow_mut_unchecked ( )
107111 . non_glob_decl
108112 . replace ( decl)
@@ -279,8 +283,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
279283 . unwrap_or_else ( || res. def_id ( ) ) ,
280284 )
281285 } ;
282- let ModChild { ident, res, vis, ref reexport_chain } = * child;
283- let ident = Macros20NormalizedIdent :: new ( ident ) ;
286+ let ModChild { ident : orig_ident , res, vis, ref reexport_chain } = * child;
287+ let ident = IdentKey :: new ( orig_ident ) ;
284288 let span = child_span ( self , reexport_chain, res) ;
285289 let res = res. expect_non_local ( ) ;
286290 let expansion = parent_scope. expansion ;
@@ -293,7 +297,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
293297
294298 // Record primary definitions.
295299 let define_extern = |ns| {
296- self . define_extern ( parent, ident, ns, child_index, res, vis, span, expansion, ambig)
300+ self . define_extern (
301+ parent,
302+ ident,
303+ orig_ident. span ,
304+ ns,
305+ child_index,
306+ res,
307+ vis,
308+ span,
309+ expansion,
310+ ambig,
311+ )
297312 } ;
298313 match res {
299314 Res :: Def (
@@ -533,8 +548,8 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
533548 if target. name != kw:: Underscore {
534549 self . r . per_ns ( |this, ns| {
535550 if !type_ns_only || ns == TypeNS {
536- let key = BindingKey :: new ( Macros20NormalizedIdent :: new ( target) , ns) ;
537- this. resolution_or_default ( current_module, key)
551+ let key = BindingKey :: new ( IdentKey :: new ( target) , ns) ;
552+ this. resolution_or_default ( current_module, key, target . span )
538553 . borrow_mut ( this)
539554 . single_imports
540555 . insert ( import) ;
@@ -971,7 +986,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
971986 & mut self ,
972987 orig_name : Option < Symbol > ,
973988 item : & Item ,
974- ident : Ident ,
989+ orig_ident : Ident ,
975990 local_def_id : LocalDefId ,
976991 vis : Visibility ,
977992 ) {
@@ -980,7 +995,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
980995 let parent = parent_scope. module ;
981996 let expansion = parent_scope. expansion ;
982997
983- let ( used, module, decl) = if orig_name. is_none ( ) && ident . name == kw:: SelfLower {
998+ let ( used, module, decl) = if orig_name. is_none ( ) && orig_ident . name == kw:: SelfLower {
984999 self . r . dcx ( ) . emit_err ( errors:: ExternCrateSelfRequiresRenaming { span : sp } ) ;
9851000 return ;
9861001 } else if orig_name == Some ( kw:: SelfLower ) {
@@ -1005,7 +1020,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
10051020 } )
10061021 . unwrap_or ( ( true , None , self . r . dummy_decl ) ) ;
10071022 let import = self . r . arenas . alloc_import ( ImportData {
1008- kind : ImportKind :: ExternCrate { source : orig_name, target : ident , id : item. id } ,
1023+ kind : ImportKind :: ExternCrate { source : orig_name, target : orig_ident , id : item. id } ,
10091024 root_id : item. id ,
10101025 parent_scope,
10111026 imported_module : CmCell :: new ( module) ,
@@ -1023,7 +1038,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
10231038 }
10241039 self . r . potentially_unused_imports . push ( import) ;
10251040 let import_decl = self . r . new_import_decl ( decl, import) ;
1026- let ident = Macros20NormalizedIdent :: new ( ident ) ;
1041+ let ident = IdentKey :: new ( orig_ident ) ;
10271042 if ident. name != kw:: Underscore && parent == self . r . graph_root {
10281043 // FIXME: this error is technically unnecessary now when extern prelude is split into
10291044 // two scopes, remove it with lang team approval.
@@ -1042,20 +1057,20 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
10421057 Entry :: Occupied ( mut occupied) => {
10431058 let entry = occupied. get_mut ( ) ;
10441059 if entry. item_decl . is_some ( ) {
1045- let msg = format ! ( "extern crate `{ident }` already in extern prelude" ) ;
1060+ let msg = format ! ( "extern crate `{orig_ident }` already in extern prelude" ) ;
10461061 self . r . tcx . dcx ( ) . span_delayed_bug ( item. span , msg) ;
10471062 } else {
1048- entry. item_decl = Some ( ( import_decl, orig_name. is_some ( ) ) ) ;
1063+ entry. item_decl = Some ( ( import_decl, orig_ident . span , orig_name. is_some ( ) ) ) ;
10491064 }
10501065 entry
10511066 }
10521067 Entry :: Vacant ( vacant) => vacant. insert ( ExternPreludeEntry {
1053- item_decl : Some ( ( import_decl, true ) ) ,
1068+ item_decl : Some ( ( import_decl, orig_ident . span , true ) ) ,
10541069 flag_decl : None ,
10551070 } ) ,
10561071 } ;
10571072 }
1058- self . r . plant_decl_into_local_module ( ident, TypeNS , import_decl) ;
1073+ self . r . plant_decl_into_local_module ( ident, orig_ident . span , TypeNS , import_decl) ;
10591074 }
10601075
10611076 /// Constructs the reduced graph for one foreign item.
@@ -1156,7 +1171,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
11561171 if let Some ( span) = import_all {
11571172 let import = macro_use_import ( self , span, false ) ;
11581173 self . r . potentially_unused_imports . push ( import) ;
1159- module. for_each_child_mut ( self , |this, ident, ns, binding| {
1174+ module. for_each_child_mut ( self , |this, ident, _ , ns, binding| {
11601175 if ns == MacroNS {
11611176 let import =
11621177 if this. r . is_accessible_from ( binding. vis ( ) , this. parent_scope . module ) {
@@ -1267,7 +1282,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
12671282 let expansion = parent_scope. expansion ;
12681283 let feed = self . r . feed ( item. id ) ;
12691284 let def_id = feed. key ( ) ;
1270- let ( res, ident , span, macro_rules) = match & item. kind {
1285+ let ( res, orig_ident , span, macro_rules) = match & item. kind {
12711286 ItemKind :: MacroDef ( ident, def) => {
12721287 ( self . res ( def_id) , * ident, item. span , def. macro_rules )
12731288 }
@@ -1290,8 +1305,8 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
12901305 self . r . local_macro_def_scopes . insert ( def_id, parent_scope. module ) ;
12911306
12921307 if macro_rules {
1293- let ident = Macros20NormalizedIdent :: new ( ident ) ;
1294- self . r . macro_names . insert ( ident. 0 ) ;
1308+ let ident = IdentKey :: new ( orig_ident ) ;
1309+ self . r . macro_names . insert ( ident) ;
12951310 let is_macro_export = ast:: attr:: contains_name ( & item. attrs , sym:: macro_export) ;
12961311 let vis = if is_macro_export {
12971312 Visibility :: Public
@@ -1323,17 +1338,18 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
13231338 } ) ;
13241339 self . r . import_use_map . insert ( import, Used :: Other ) ;
13251340 let import_decl = self . r . new_import_decl ( decl, import) ;
1326- self . r . plant_decl_into_local_module ( ident, MacroNS , import_decl) ;
1341+ self . r . plant_decl_into_local_module ( ident, orig_ident . span , MacroNS , import_decl) ;
13271342 } else {
1328- self . r . check_reserved_macro_name ( ident. 0 , res) ;
1329- self . insert_unused_macro ( ident . 0 , def_id, item. id ) ;
1343+ self . r . check_reserved_macro_name ( ident. name , orig_ident . span , res) ;
1344+ self . insert_unused_macro ( orig_ident , def_id, item. id ) ;
13301345 }
13311346 self . r . feed_visibility ( feed, vis) ;
13321347 let scope = self . r . arenas . alloc_macro_rules_scope ( MacroRulesScope :: Def (
13331348 self . r . arenas . alloc_macro_rules_decl ( MacroRulesDecl {
13341349 parent_macro_rules_scope : parent_scope. macro_rules ,
13351350 decl,
13361351 ident,
1352+ orig_ident_span : orig_ident. span ,
13371353 } ) ,
13381354 ) ) ;
13391355 self . r . macro_rules_scopes . insert ( def_id, scope) ;
@@ -1349,9 +1365,9 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
13491365 _ => self . resolve_visibility ( & item. vis ) ,
13501366 } ;
13511367 if !vis. is_public ( ) {
1352- self . insert_unused_macro ( ident , def_id, item. id ) ;
1368+ self . insert_unused_macro ( orig_ident , def_id, item. id ) ;
13531369 }
1354- self . r . define_local ( module, ident , MacroNS , res, vis, span, expansion) ;
1370+ self . r . define_local ( module, orig_ident , MacroNS , res, vis, span, expansion) ;
13551371 self . r . feed_visibility ( feed, vis) ;
13561372 self . parent_scope . macro_rules
13571373 }
@@ -1493,7 +1509,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
14931509 {
14941510 // Don't add underscore names, they cannot be looked up anyway.
14951511 let impl_def_id = self . r . tcx . local_parent ( local_def_id) ;
1496- let key = BindingKey :: new ( Macros20NormalizedIdent :: new ( ident) , ns) ;
1512+ let key = BindingKey :: new ( IdentKey :: new ( ident) , ns) ;
14971513 self . r . impl_binding_keys . entry ( impl_def_id) . or_default ( ) . insert ( key) ;
14981514 }
14991515
0 commit comments