@@ -54,9 +54,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
5454 mut self : CmResolver < ' r , ' ra , ' tcx > ,
5555 scope_set : ScopeSet < ' ra > ,
5656 parent_scope : & ParentScope < ' ra > ,
57- // Location of the span is not significant, but pass a `Span` instead of `SyntaxContext`
58- // to avoid extracting and re-packaging the syntax context unnecessarily.
59- orig_ctxt : Span ,
57+ mut ctxt : Macros20NormalizedSyntaxContext ,
58+ orig_ident_span : Span ,
6059 derive_fallback_lint_id : Option < NodeId > ,
6160 mut visitor : impl FnMut (
6261 CmResolver < ' _ , ' ra , ' tcx > ,
@@ -128,7 +127,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
128127 TypeNS | ValueNS => Scope :: ModuleNonGlobs ( module, None ) ,
129128 MacroNS => Scope :: DeriveHelpers ( parent_scope. expansion ) ,
130129 } ;
131- let mut ctxt = Macros20NormalizedSyntaxContext :: new ( orig_ctxt. ctxt ( ) ) ;
132130 let mut use_prelude = !module. no_implicit_prelude ;
133131
134132 loop {
@@ -153,7 +151,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
153151 true
154152 }
155153 Scope :: ModuleNonGlobs ( ..) | Scope :: ModuleGlobs ( ..) => true ,
156- Scope :: MacroUsePrelude => use_prelude || orig_ctxt . edition ( ) . is_rust_2015 ( ) ,
154+ Scope :: MacroUsePrelude => use_prelude || orig_ident_span . is_rust_2015 ( ) ,
157155 Scope :: BuiltinAttrs => true ,
158156 Scope :: ExternPreludeItems | Scope :: ExternPreludeFlags => {
159157 use_prelude || module_and_extern_prelude || extern_prelude
@@ -388,8 +386,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
388386 unreachable ! ( )
389387 }
390388
391- /// Resolve an identifier in the specified set of scopes.
392- #[ instrument( level = "debug" , skip( self ) ) ]
393389 pub ( crate ) fn resolve_ident_in_scope_set < ' r > (
394390 self : CmResolver < ' r , ' ra , ' tcx > ,
395391 orig_ident : Ident ,
@@ -399,11 +395,36 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
399395 force : bool ,
400396 ignore_decl : Option < Decl < ' ra > > ,
401397 ignore_import : Option < Import < ' ra > > ,
398+ ) -> Result < Decl < ' ra > , Determinacy > {
399+ self . resolve_ident_in_scope_set_inner (
400+ IdentKey :: new ( orig_ident) ,
401+ orig_ident. span ,
402+ scope_set,
403+ parent_scope,
404+ finalize,
405+ force,
406+ ignore_decl,
407+ ignore_import,
408+ )
409+ }
410+
411+ /// Resolve an identifier in the specified set of scopes.
412+ #[ instrument( level = "debug" , skip( self ) ) ]
413+ fn resolve_ident_in_scope_set_inner < ' r > (
414+ self : CmResolver < ' r , ' ra , ' tcx > ,
415+ ident : IdentKey ,
416+ orig_ident_span : Span ,
417+ scope_set : ScopeSet < ' ra > ,
418+ parent_scope : & ParentScope < ' ra > ,
419+ finalize : Option < Finalize > ,
420+ force : bool ,
421+ ignore_decl : Option < Decl < ' ra > > ,
422+ ignore_import : Option < Import < ' ra > > ,
402423 ) -> Result < Decl < ' ra > , Determinacy > {
403424 assert ! ( force || finalize. is_none( ) ) ; // `finalize` implies `force`
404425
405426 // Make sure `self`, `super` etc produce an error when passed to here.
406- if !matches ! ( scope_set, ScopeSet :: Module ( ..) ) && orig_ident . is_path_segment_keyword ( ) {
427+ if !matches ! ( scope_set, ScopeSet :: Module ( ..) ) && ident . name . is_path_segment_keyword ( ) {
407428 return Err ( Determinacy :: Determined ) ;
408429 }
409430
@@ -437,13 +458,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
437458 let break_result = self . visit_scopes (
438459 scope_set,
439460 parent_scope,
440- orig_ident. span ,
461+ ident. ctxt ,
462+ orig_ident_span,
441463 derive_fallback_lint_id,
442464 |mut this, scope, use_prelude, ctxt| {
443- let ident = IdentKey { name : orig_ident . name , ctxt } ;
465+ let ident = IdentKey { name : ident . name , ctxt } ;
444466 let res = match this. reborrow ( ) . resolve_ident_in_scope (
445467 ident,
446- orig_ident . span ,
468+ orig_ident_span ,
447469 ns,
448470 scope,
449471 use_prelude,
@@ -478,7 +500,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
478500 if let Some ( & ( innermost_decl, _) ) = innermost_results. first ( ) {
479501 // Found another solution, if the first one was "weak", report an error.
480502 if this. get_mut ( ) . maybe_push_ambiguity (
481- orig_ident,
503+ ident,
504+ orig_ident_span,
482505 ns,
483506 scope_set,
484507 parent_scope,
@@ -710,8 +733,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
710733 Scope :: StdLibPrelude => {
711734 let mut result = Err ( Determinacy :: Determined ) ;
712735 if let Some ( prelude) = self . prelude
713- && let Ok ( decl) = self . reborrow ( ) . resolve_ident_in_scope_set (
714- ident. orig ( orig_ident_span. with_ctxt ( * ident. ctxt ) ) ,
736+ && let Ok ( decl) = self . reborrow ( ) . resolve_ident_in_scope_set_inner (
737+ ident,
738+ orig_ident_span,
715739 ScopeSet :: Module ( ns, prelude) ,
716740 parent_scope,
717741 None ,
@@ -765,7 +789,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
765789
766790 fn maybe_push_ambiguity (
767791 & mut self ,
768- orig_ident : Ident ,
792+ ident : IdentKey ,
793+ orig_ident_span : Span ,
769794 ns : Namespace ,
770795 scope_set : ScopeSet < ' ra > ,
771796 parent_scope : & ParentScope < ' ra > ,
@@ -791,7 +816,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
791816 } else if innermost_res == derive_helper_compat {
792817 Some ( AmbiguityKind :: DeriveHelper )
793818 } else if res == derive_helper_compat && innermost_res != derive_helper {
794- span_bug ! ( orig_ident . span , "impossible inner resolution kind" )
819+ span_bug ! ( orig_ident_span , "impossible inner resolution kind" )
795820 } else if matches ! ( innermost_scope, Scope :: MacroRules ( _) )
796821 && matches ! ( scope, Scope :: ModuleNonGlobs ( ..) | Scope :: ModuleGlobs ( ..) )
797822 && !self . disambiguate_macro_rules_vs_modularized ( innermost_decl, decl)
@@ -806,7 +831,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
806831 // we visit all macro_rules scopes (e.g. textual scope macros)
807832 // before we visit any modules (e.g. path-based scope macros)
808833 span_bug ! (
809- orig_ident . span ,
834+ orig_ident_span ,
810835 "ambiguous scoped macro resolutions with path-based \
811836 scope resolution as first candidate"
812837 )
@@ -855,8 +880,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
855880 } else {
856881 // Turn ambiguity errors for core vs std panic into warnings.
857882 // FIXME: Remove with lang team approval.
858- let is_issue_147319_hack = orig_ident . span . edition ( ) <= Edition :: Edition2024
859- && matches ! ( orig_ident . name, sym:: panic)
883+ let is_issue_147319_hack = orig_ident_span . edition ( ) <= Edition :: Edition2024
884+ && matches ! ( ident . name, sym:: panic)
860885 && matches ! ( scope, Scope :: StdLibPrelude )
861886 && matches ! ( innermost_scope, Scope :: ModuleGlobs ( _, _) )
862887 && ( ( self . is_specific_builtin_macro ( res, sym:: std_panic)
@@ -868,7 +893,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
868893
869894 self . ambiguity_errors . push ( AmbiguityError {
870895 kind,
871- ident : orig_ident ,
896+ ident : ident . orig ( orig_ident_span ) ,
872897 b1 : innermost_decl,
873898 b2 : decl,
874899 scope1 : innermost_scope,
@@ -1165,8 +1190,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11651190 None => return Err ( ControlFlow :: Continue ( Undetermined ) ) ,
11661191 } ;
11671192 let tmp_parent_scope;
1168- let ( mut adjusted_parent_scope, mut ctxt) = ( parent_scope, * ident. ctxt ) ;
1169- match ctxt. glob_adjust ( module. expansion , glob_import. span ) {
1193+ let ( mut adjusted_parent_scope, mut adjusted_ident) = ( parent_scope, ident) ;
1194+ match adjusted_ident
1195+ . ctxt
1196+ . update_unchecked ( |ctxt| ctxt. glob_adjust ( module. expansion , glob_import. span ) )
1197+ {
11701198 Some ( Some ( def) ) => {
11711199 tmp_parent_scope =
11721200 ParentScope { module : self . expn_def_scope ( def) , ..* parent_scope } ;
@@ -1175,8 +1203,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11751203 Some ( None ) => { }
11761204 None => continue ,
11771205 } ;
1178- let result = self . reborrow ( ) . resolve_ident_in_scope_set (
1179- ident. orig ( orig_ident_span. with_ctxt ( ctxt) ) ,
1206+ let result = self . reborrow ( ) . resolve_ident_in_scope_set_inner (
1207+ adjusted_ident,
1208+ orig_ident_span,
11801209 ScopeSet :: Module ( ns, module) ,
11811210 adjusted_parent_scope,
11821211 None ,
0 commit comments