@@ -9,7 +9,7 @@ use rustc_middle::{bug, span_bug};
99use rustc_session:: lint:: builtin:: PROC_MACRO_DERIVE_RESOLUTION_FALLBACK ;
1010use rustc_session:: parse:: feature_err;
1111use rustc_span:: hygiene:: { ExpnId , ExpnKind , LocalExpnId , MacroKind , SyntaxContext } ;
12- use rustc_span:: { Ident , Span , kw, sym} ;
12+ use rustc_span:: { Ident , Macros20NormalizedIdent , Span , kw, sym} ;
1313use tracing:: { debug, instrument} ;
1414
1515use crate :: errors:: { ParamKindInEnumDiscriminant , ParamKindInNonTrivialAnonConst } ;
@@ -51,7 +51,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
5151 mut self : CmResolver < ' r , ' ra , ' tcx > ,
5252 scope_set : ScopeSet < ' ra > ,
5353 parent_scope : & ParentScope < ' ra > ,
54- ctxt : SyntaxContext ,
54+ orig_ctxt : SyntaxContext ,
5555 derive_fallback_lint_id : Option < NodeId > ,
5656 mut visitor : impl FnMut (
5757 & mut CmResolver < ' r , ' ra , ' tcx > ,
@@ -101,7 +101,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
101101 // 4c. Standard library prelude (de-facto closed, controlled).
102102 // 6. Language prelude: builtin attributes (closed, controlled).
103103
104- let rust_2015 = ctxt. edition ( ) . is_rust_2015 ( ) ;
105104 let ( ns, macro_kind) = match scope_set {
106105 ScopeSet :: All ( ns)
107106 | ScopeSet :: Module ( ns, _)
@@ -124,7 +123,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
124123 TypeNS | ValueNS => Scope :: ModuleNonGlobs ( module, None ) ,
125124 MacroNS => Scope :: DeriveHelpers ( parent_scope. expansion ) ,
126125 } ;
127- let mut ctxt = ctxt . normalize_to_macros_2_0 ( ) ;
126+ let mut ctxt = orig_ctxt . normalize_to_macros_2_0 ( ) ;
128127 let mut use_prelude = !module. no_implicit_prelude ;
129128
130129 loop {
@@ -149,7 +148,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
149148 true
150149 }
151150 Scope :: ModuleNonGlobs ( ..) | Scope :: ModuleGlobs ( ..) => true ,
152- Scope :: MacroUsePrelude => use_prelude || rust_2015 ,
151+ Scope :: MacroUsePrelude => use_prelude || orig_ctxt . edition ( ) . is_rust_2015 ( ) ,
153152 Scope :: BuiltinAttrs => true ,
154153 Scope :: ExternPreludeItems | Scope :: ExternPreludeFlags => {
155154 use_prelude || module_and_extern_prelude || extern_prelude
@@ -435,12 +434,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
435434 orig_ident. span . ctxt ( ) ,
436435 derive_fallback_lint_id,
437436 |this, scope, use_prelude, ctxt| {
437+ let ident = Ident :: new ( orig_ident. name , orig_ident. span . with_ctxt ( ctxt) ) ;
438+ // The passed `ctxt` is already normalized, so avoid expensive double normalization.
439+ let ident = Macros20NormalizedIdent ( ident) ;
438440 let res = match this. reborrow ( ) . resolve_ident_in_scope (
439- orig_ident ,
441+ ident ,
440442 ns,
441443 scope,
442444 use_prelude,
443- ctxt,
444445 scope_set,
445446 parent_scope,
446447 // Shadowed bindings don't need to be marked as used or non-speculatively loaded.
@@ -509,19 +510,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
509510
510511 fn resolve_ident_in_scope < ' r > (
511512 mut self : CmResolver < ' r , ' ra , ' tcx > ,
512- orig_ident : Ident ,
513+ ident : Macros20NormalizedIdent ,
513514 ns : Namespace ,
514515 scope : Scope < ' ra > ,
515516 use_prelude : UsePrelude ,
516- ctxt : SyntaxContext ,
517517 scope_set : ScopeSet < ' ra > ,
518518 parent_scope : & ParentScope < ' ra > ,
519519 finalize : Option < Finalize > ,
520520 force : bool ,
521521 ignore_binding : Option < NameBinding < ' ra > > ,
522522 ignore_import : Option < Import < ' ra > > ,
523523 ) -> Result < NameBinding < ' ra > , ControlFlow < Determinacy , Determinacy > > {
524- let ident = Ident :: new ( orig_ident. name , orig_ident. span . with_ctxt ( ctxt) ) ;
525524 let ret = match scope {
526525 Scope :: DeriveHelpers ( expn_id) => {
527526 if let Some ( binding) = self . helper_attrs . get ( & expn_id) . and_then ( |attrs| {
@@ -600,11 +599,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
600599 self . get_mut ( ) . lint_buffer . buffer_lint (
601600 PROC_MACRO_DERIVE_RESOLUTION_FALLBACK ,
602601 lint_id,
603- orig_ident . span ,
602+ ident . span ,
604603 errors:: ProcMacroDeriveResolutionFallback {
605- span : orig_ident . span ,
604+ span : ident . span ,
606605 ns_descr : ns. descr ( ) ,
607- ident,
606+ ident : ident . 0 ,
608607 } ,
609608 ) ;
610609 }
@@ -650,11 +649,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
650649 self . get_mut ( ) . lint_buffer . buffer_lint (
651650 PROC_MACRO_DERIVE_RESOLUTION_FALLBACK ,
652651 lint_id,
653- orig_ident . span ,
652+ ident . span ,
654653 errors:: ProcMacroDeriveResolutionFallback {
655- span : orig_ident . span ,
654+ span : ident . span ,
656655 ns_descr : ns. descr ( ) ,
657- ident,
656+ ident : ident . 0 ,
658657 } ,
659658 ) ;
660659 }
@@ -700,7 +699,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
700699 let mut result = Err ( Determinacy :: Determined ) ;
701700 if let Some ( prelude) = self . prelude
702701 && let Ok ( binding) = self . reborrow ( ) . resolve_ident_in_scope_set (
703- ident,
702+ ident. 0 ,
704703 ScopeSet :: Module ( ns, prelude) ,
705704 parent_scope,
706705 None ,
@@ -987,7 +986,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
987986 fn resolve_ident_in_module_non_globs_unadjusted < ' r > (
988987 mut self : CmResolver < ' r , ' ra , ' tcx > ,
989988 module : Module < ' ra > ,
990- ident : Ident ,
989+ ident : Macros20NormalizedIdent ,
991990 ns : Namespace ,
992991 parent_scope : & ParentScope < ' ra > ,
993992 shadowing : Shadowing ,
@@ -1010,7 +1009,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10101009
10111010 if let Some ( finalize) = finalize {
10121011 return self . get_mut ( ) . finalize_module_binding (
1013- ident,
1012+ ident. 0 ,
10141013 binding,
10151014 parent_scope,
10161015 module,
@@ -1050,7 +1049,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10501049 fn resolve_ident_in_module_globs_unadjusted < ' r > (
10511050 mut self : CmResolver < ' r , ' ra , ' tcx > ,
10521051 module : Module < ' ra > ,
1053- ident : Ident ,
1052+ ident : Macros20NormalizedIdent ,
10541053 ns : Namespace ,
10551054 parent_scope : & ParentScope < ' ra > ,
10561055 shadowing : Shadowing ,
@@ -1071,7 +1070,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10711070
10721071 if let Some ( finalize) = finalize {
10731072 return self . get_mut ( ) . finalize_module_binding (
1074- ident,
1073+ ident. 0 ,
10751074 binding,
10761075 parent_scope,
10771076 module,
@@ -1140,9 +1139,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11401139 None => return Err ( ControlFlow :: Continue ( Undetermined ) ) ,
11411140 } ;
11421141 let tmp_parent_scope;
1143- let ( mut adjusted_parent_scope, mut ident) =
1144- ( parent_scope, ident. normalize_to_macros_2_0 ( ) ) ;
1145- match ident. span . glob_adjust ( module. expansion , glob_import. span ) {
1142+ let ( mut adjusted_parent_scope, mut ident) = ( parent_scope, ident) ;
1143+ match ident. 0 . span . glob_adjust ( module. expansion , glob_import. span ) {
11461144 Some ( Some ( def) ) => {
11471145 tmp_parent_scope =
11481146 ParentScope { module : self . expn_def_scope ( def) , ..* parent_scope } ;
@@ -1152,7 +1150,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11521150 None => continue ,
11531151 } ;
11541152 let result = self . reborrow ( ) . resolve_ident_in_scope_set (
1155- ident,
1153+ ident. 0 ,
11561154 ScopeSet :: Module ( ns, module) ,
11571155 adjusted_parent_scope,
11581156 None ,
0 commit comments