@@ -71,7 +71,7 @@ use rustc_query_system::ich::StableHashingContext;
7171use rustc_session:: lint:: builtin:: PRIVATE_MACRO_USE ;
7272use rustc_session:: lint:: { BuiltinLintDiag , LintBuffer } ;
7373use rustc_span:: hygiene:: { ExpnId , LocalExpnId , MacroKind , SyntaxContext , Transparency } ;
74- use rustc_span:: { DUMMY_SP , Ident , Span , Symbol , kw, sym} ;
74+ use rustc_span:: { DUMMY_SP , Ident , Macros20NormalizedIdent , Span , Symbol , kw, sym} ;
7575use smallvec:: { SmallVec , smallvec} ;
7676use tracing:: debug;
7777
@@ -531,7 +531,7 @@ impl ModuleKind {
531531struct BindingKey {
532532 /// The identifier for the binding, always the `normalize_to_macros_2_0` version of the
533533 /// identifier.
534- ident : Ident ,
534+ ident : Macros20NormalizedIdent ,
535535 ns : Namespace ,
536536 /// When we add an underscore binding (with ident `_`) to some module, this field has
537537 /// a non-zero value that uniquely identifies this binding in that module.
@@ -543,7 +543,7 @@ struct BindingKey {
543543
544544impl BindingKey {
545545 fn new ( ident : Ident , ns : Namespace ) -> Self {
546- BindingKey { ident : ident . normalize_to_macros_2_0 ( ) , ns, disambiguator : 0 }
546+ BindingKey { ident : Macros20NormalizedIdent :: new ( ident ) , ns, disambiguator : 0 }
547547 }
548548
549549 fn new_disambiguated (
@@ -552,7 +552,7 @@ impl BindingKey {
552552 disambiguator : impl FnOnce ( ) -> u32 ,
553553 ) -> BindingKey {
554554 let disambiguator = if ident. name == kw:: Underscore { disambiguator ( ) } else { 0 } ;
555- BindingKey { ident : ident . normalize_to_macros_2_0 ( ) , ns, disambiguator }
555+ BindingKey { ident : Macros20NormalizedIdent :: new ( ident ) , ns, disambiguator }
556556 }
557557}
558558
@@ -659,7 +659,7 @@ impl<'ra> Module<'ra> {
659659 fn for_each_child < ' tcx , R : AsRef < Resolver < ' ra , ' tcx > > > (
660660 self ,
661661 resolver : & R ,
662- mut f : impl FnMut ( & R , Ident , Namespace , NameBinding < ' ra > ) ,
662+ mut f : impl FnMut ( & R , Macros20NormalizedIdent , Namespace , NameBinding < ' ra > ) ,
663663 ) {
664664 for ( key, name_resolution) in resolver. as_ref ( ) . resolutions ( self ) . borrow ( ) . iter ( ) {
665665 if let Some ( binding) = name_resolution. borrow ( ) . best_binding ( ) {
@@ -671,7 +671,7 @@ impl<'ra> Module<'ra> {
671671 fn for_each_child_mut < ' tcx , R : AsMut < Resolver < ' ra , ' tcx > > > (
672672 self ,
673673 resolver : & mut R ,
674- mut f : impl FnMut ( & mut R , Ident , Namespace , NameBinding < ' ra > ) ,
674+ mut f : impl FnMut ( & mut R , Macros20NormalizedIdent , Namespace , NameBinding < ' ra > ) ,
675675 ) {
676676 for ( key, name_resolution) in resolver. as_mut ( ) . resolutions ( self ) . borrow ( ) . iter ( ) {
677677 if let Some ( binding) = name_resolution. borrow ( ) . best_binding ( ) {
@@ -690,7 +690,7 @@ impl<'ra> Module<'ra> {
690690 return ;
691691 }
692692 if let Res :: Def ( DefKind :: Trait | DefKind :: TraitAlias , def_id) = binding. res ( ) {
693- collected_traits. push ( ( name, binding, r. as_ref ( ) . get_module ( def_id) ) )
693+ collected_traits. push ( ( name. 0 , binding, r. as_ref ( ) . get_module ( def_id) ) )
694694 }
695695 } ) ;
696696 * traits = Some ( collected_traits. into_boxed_slice ( ) ) ;
@@ -1049,7 +1049,7 @@ pub struct Resolver<'ra, 'tcx> {
10491049 graph_root : Module < ' ra > ,
10501050
10511051 prelude : Option < Module < ' ra > > ,
1052- extern_prelude : FxIndexMap < Ident , ExternPreludeEntry < ' ra > > ,
1052+ extern_prelude : FxIndexMap < Macros20NormalizedIdent , ExternPreludeEntry < ' ra > > ,
10531053
10541054 /// N.B., this is used only for better diagnostics, not name resolution itself.
10551055 field_names : LocalDefIdMap < Vec < Ident > > ,
@@ -1482,19 +1482,28 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14821482 let mut invocation_parents = FxHashMap :: default ( ) ;
14831483 invocation_parents. insert ( LocalExpnId :: ROOT , InvocationParent :: ROOT ) ;
14841484
1485- let mut extern_prelude: FxIndexMap < Ident , ExternPreludeEntry < ' _ > > = tcx
1485+ let mut extern_prelude: FxIndexMap < Macros20NormalizedIdent , ExternPreludeEntry < ' _ > > = tcx
14861486 . sess
14871487 . opts
14881488 . externs
14891489 . iter ( )
14901490 . filter ( |( _, entry) | entry. add_prelude )
1491- . map ( |( name, _) | ( Ident :: from_str ( name) , Default :: default ( ) ) )
1491+ . map ( |( name, _) | {
1492+ (
1493+ unsafe {
1494+ Macros20NormalizedIdent :: new_without_normalize ( Ident :: from_str ( name) )
1495+ } ,
1496+ Default :: default ( ) ,
1497+ )
1498+ } )
14921499 . collect ( ) ;
14931500
14941501 if !attr:: contains_name ( attrs, sym:: no_core) {
1495- extern_prelude. insert ( Ident :: with_dummy_span ( sym:: core) , Default :: default ( ) ) ;
1502+ extern_prelude
1503+ . insert ( Macros20NormalizedIdent :: with_dummy_span ( sym:: core) , Default :: default ( ) ) ;
14961504 if !attr:: contains_name ( attrs, sym:: no_std) {
1497- extern_prelude. insert ( Ident :: with_dummy_span ( sym:: std) , Default :: default ( ) ) ;
1505+ extern_prelude
1506+ . insert ( Macros20NormalizedIdent :: with_dummy_span ( sym:: std) , Default :: default ( ) ) ;
14981507 }
14991508 }
15001509
@@ -2005,7 +2014,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20052014 // Avoid marking `extern crate` items that refer to a name from extern prelude,
20062015 // but not introduce it, as used if they are accessed from lexical scope.
20072016 if used == Used :: Scope {
2008- if let Some ( entry) = self . extern_prelude . get ( & ident . normalize_to_macros_2_0 ( ) ) {
2017+ if let Some ( entry) = self . extern_prelude . get ( & Macros20NormalizedIdent :: new ( ident ) ) {
20092018 if !entry. introduced_by_item && entry. binding == Some ( used_binding) {
20102019 return ;
20112020 }
@@ -2168,7 +2177,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
21682177 return None ;
21692178 }
21702179
2171- let norm_ident = ident . normalize_to_macros_2_0 ( ) ;
2180+ let norm_ident = Macros20NormalizedIdent :: new ( ident ) ;
21722181 let binding = self . extern_prelude . get ( & norm_ident) . cloned ( ) . and_then ( |entry| {
21732182 Some ( if let Some ( binding) = entry. binding {
21742183 if finalize {
0 commit comments