@@ -9,7 +9,8 @@ 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} ;
13+ use smallvec:: SmallVec ;
1314use tracing:: { debug, instrument} ;
1415
1516use crate :: errors:: { ParamKindInEnumDiscriminant , ParamKindInNonTrivialAnonConst } ;
@@ -50,7 +51,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
5051 mut self : CmResolver < ' r , ' ra , ' tcx > ,
5152 scope_set : ScopeSet < ' ra > ,
5253 parent_scope : & ParentScope < ' ra > ,
53- ctxt : SyntaxContext ,
54+ orig_ctxt : SyntaxContext ,
5455 derive_fallback_lint_id : Option < NodeId > ,
5556 mut visitor : impl FnMut (
5657 & mut CmResolver < ' r , ' ra , ' tcx > ,
@@ -100,7 +101,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
100101 // 4c. Standard library prelude (de-facto closed, controlled).
101102 // 6. Language prelude: builtin attributes (closed, controlled).
102103
103- let rust_2015 = ctxt. edition ( ) . is_rust_2015 ( ) ;
104104 let ( ns, macro_kind) = match scope_set {
105105 ScopeSet :: All ( ns)
106106 | ScopeSet :: Module ( ns, _)
@@ -123,7 +123,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
123123 TypeNS | ValueNS => Scope :: ModuleNonGlobs ( module, None ) ,
124124 MacroNS => Scope :: DeriveHelpers ( parent_scope. expansion ) ,
125125 } ;
126- let mut ctxt = ctxt . normalize_to_macros_2_0 ( ) ;
126+ let mut ctxt = orig_ctxt . normalize_to_macros_2_0 ( ) ;
127127 let mut use_prelude = !module. no_implicit_prelude ;
128128
129129 loop {
@@ -148,7 +148,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
148148 true
149149 }
150150 Scope :: ModuleNonGlobs ( ..) | Scope :: ModuleGlobs ( ..) => true ,
151- Scope :: MacroUsePrelude => use_prelude || rust_2015 ,
151+ Scope :: MacroUsePrelude => use_prelude || orig_ctxt . edition ( ) . is_rust_2015 ( ) ,
152152 Scope :: BuiltinAttrs => true ,
153153 Scope :: ExternPreludeItems | Scope :: ExternPreludeFlags => {
154154 use_prelude || module_and_extern_prelude || extern_prelude
@@ -397,7 +397,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
397397 assert ! ( force || finalize. is_none( ) ) ; // `finalize` implies `force`
398398
399399 // Make sure `self`, `super` etc produce an error when passed to here.
400- if orig_ident . is_path_segment_keyword ( ) && !matches ! ( scope_set, ScopeSet :: Module ( ..) ) {
400+ if !matches ! ( scope_set, ScopeSet :: Module ( ..) ) && orig_ident . is_path_segment_keyword ( ) {
401401 return Err ( Determinacy :: Determined ) ;
402402 }
403403
@@ -424,7 +424,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
424424 // }
425425 // So we have to save the innermost solution and continue searching in outer scopes
426426 // to detect potential ambiguities.
427- let mut innermost_results: Vec < ( Decl < ' _ > , Scope < ' _ > ) > = Vec :: new ( ) ;
427+ let mut innermost_results: SmallVec < [ ( Decl < ' _ > , Scope < ' _ > ) ; 2 ] > = SmallVec :: new ( ) ;
428428 let mut determinacy = Determinacy :: Determined ;
429429
430430 // Go through all the scopes and try to resolve the name.
@@ -434,12 +434,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
434434 orig_ident. span . ctxt ( ) ,
435435 derive_fallback_lint_id,
436436 |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) ;
437440 let res = match this. reborrow ( ) . resolve_ident_in_scope (
438- orig_ident ,
441+ ident ,
439442 ns,
440443 scope,
441444 use_prelude,
442- ctxt,
443445 scope_set,
444446 parent_scope,
445447 // Shadowed decls don't need to be marked as used or non-speculatively loaded.
@@ -508,19 +510,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
508510
509511 fn resolve_ident_in_scope < ' r > (
510512 mut self : CmResolver < ' r , ' ra , ' tcx > ,
511- orig_ident : Ident ,
513+ ident : Macros20NormalizedIdent ,
512514 ns : Namespace ,
513515 scope : Scope < ' ra > ,
514516 use_prelude : UsePrelude ,
515- ctxt : SyntaxContext ,
516517 scope_set : ScopeSet < ' ra > ,
517518 parent_scope : & ParentScope < ' ra > ,
518519 finalize : Option < Finalize > ,
519520 force : bool ,
520521 ignore_decl : Option < Decl < ' ra > > ,
521522 ignore_import : Option < Import < ' ra > > ,
522523 ) -> Result < Decl < ' ra > , ControlFlow < Determinacy , Determinacy > > {
523- let ident = Ident :: new ( orig_ident. name , orig_ident. span . with_ctxt ( ctxt) ) ;
524524 let ret = match scope {
525525 Scope :: DeriveHelpers ( expn_id) => {
526526 if let Some ( decl) = self
@@ -599,11 +599,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
599599 self . get_mut ( ) . lint_buffer . buffer_lint (
600600 PROC_MACRO_DERIVE_RESOLUTION_FALLBACK ,
601601 lint_id,
602- orig_ident . span ,
602+ ident . span ,
603603 errors:: ProcMacroDeriveResolutionFallback {
604- span : orig_ident . span ,
604+ span : ident . span ,
605605 ns_descr : ns. descr ( ) ,
606- ident,
606+ ident : ident . 0 ,
607607 } ,
608608 ) ;
609609 }
@@ -649,11 +649,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
649649 self . get_mut ( ) . lint_buffer . buffer_lint (
650650 PROC_MACRO_DERIVE_RESOLUTION_FALLBACK ,
651651 lint_id,
652- orig_ident . span ,
652+ ident . span ,
653653 errors:: ProcMacroDeriveResolutionFallback {
654- span : orig_ident . span ,
654+ span : ident . span ,
655655 ns_descr : ns. descr ( ) ,
656- ident,
656+ ident : ident . 0 ,
657657 } ,
658658 ) ;
659659 }
@@ -699,7 +699,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
699699 let mut result = Err ( Determinacy :: Determined ) ;
700700 if let Some ( prelude) = self . prelude
701701 && let Ok ( decl) = self . reborrow ( ) . resolve_ident_in_scope_set (
702- ident,
702+ ident. 0 ,
703703 ScopeSet :: Module ( ns, prelude) ,
704704 parent_scope,
705705 None ,
@@ -983,7 +983,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
983983 fn resolve_ident_in_module_non_globs_unadjusted < ' r > (
984984 mut self : CmResolver < ' r , ' ra , ' tcx > ,
985985 module : Module < ' ra > ,
986- ident : Ident ,
986+ ident : Macros20NormalizedIdent ,
987987 ns : Namespace ,
988988 parent_scope : & ParentScope < ' ra > ,
989989 shadowing : Shadowing ,
@@ -1006,7 +1006,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10061006
10071007 if let Some ( finalize) = finalize {
10081008 return self . get_mut ( ) . finalize_module_binding (
1009- ident,
1009+ ident. 0 ,
10101010 binding,
10111011 parent_scope,
10121012 module,
@@ -1046,7 +1046,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10461046 fn resolve_ident_in_module_globs_unadjusted < ' r > (
10471047 mut self : CmResolver < ' r , ' ra , ' tcx > ,
10481048 module : Module < ' ra > ,
1049- ident : Ident ,
1049+ ident : Macros20NormalizedIdent ,
10501050 ns : Namespace ,
10511051 parent_scope : & ParentScope < ' ra > ,
10521052 shadowing : Shadowing ,
@@ -1067,7 +1067,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10671067
10681068 if let Some ( finalize) = finalize {
10691069 return self . get_mut ( ) . finalize_module_binding (
1070- ident,
1070+ ident. 0 ,
10711071 binding,
10721072 parent_scope,
10731073 module,
@@ -1136,9 +1136,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11361136 None => return Err ( ControlFlow :: Continue ( Undetermined ) ) ,
11371137 } ;
11381138 let tmp_parent_scope;
1139- let ( mut adjusted_parent_scope, mut ident) =
1140- ( parent_scope, ident. normalize_to_macros_2_0 ( ) ) ;
1141- match ident. span . glob_adjust ( module. expansion , glob_import. span ) {
1139+ let ( mut adjusted_parent_scope, mut ident) = ( parent_scope, ident) ;
1140+ match ident. 0 . span . glob_adjust ( module. expansion , glob_import. span ) {
11421141 Some ( Some ( def) ) => {
11431142 tmp_parent_scope =
11441143 ParentScope { module : self . expn_def_scope ( def) , ..* parent_scope } ;
@@ -1148,7 +1147,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11481147 None => continue ,
11491148 } ;
11501149 let result = self . reborrow ( ) . resolve_ident_in_scope_set (
1151- ident,
1150+ ident. 0 ,
11521151 ScopeSet :: Module ( ns, module) ,
11531152 adjusted_parent_scope,
11541153 None ,
0 commit comments