@@ -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
@@ -396,9 +394,30 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
396394 finalize : Option < Finalize > ,
397395 ignore_decl : Option < Decl < ' ra > > ,
398396 ignore_import : Option < Import < ' ra > > ,
397+ ) -> Result < Decl < ' ra > , Determinacy > {
398+ self . resolve_ident_in_scope_set_inner (
399+ IdentKey :: new ( orig_ident) ,
400+ orig_ident. span ,
401+ scope_set,
402+ parent_scope,
403+ finalize,
404+ ignore_decl,
405+ ignore_import,
406+ )
407+ }
408+
409+ fn resolve_ident_in_scope_set_inner < ' r > (
410+ self : CmResolver < ' r , ' ra , ' tcx > ,
411+ ident : IdentKey ,
412+ orig_ident_span : Span ,
413+ scope_set : ScopeSet < ' ra > ,
414+ parent_scope : & ParentScope < ' ra > ,
415+ finalize : Option < Finalize > ,
416+ ignore_decl : Option < Decl < ' ra > > ,
417+ ignore_import : Option < Import < ' ra > > ,
399418 ) -> Result < Decl < ' ra > , Determinacy > {
400419 // Make sure `self`, `super` etc produce an error when passed to here.
401- if !matches ! ( scope_set, ScopeSet :: Module ( ..) ) && orig_ident . is_path_segment_keyword ( ) {
420+ if !matches ! ( scope_set, ScopeSet :: Module ( ..) ) && ident . name . is_path_segment_keyword ( ) {
402421 return Err ( Determinacy :: Determined ) ;
403422 }
404423
@@ -432,13 +451,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
432451 let break_result = self . visit_scopes (
433452 scope_set,
434453 parent_scope,
435- orig_ident. span ,
454+ ident. ctxt ,
455+ orig_ident_span,
436456 derive_fallback_lint_id,
437457 |mut this, scope, use_prelude, ctxt| {
438- let ident = IdentKey { name : orig_ident . name , ctxt } ;
458+ let ident = IdentKey { name : ident . name , ctxt } ;
439459 let res = match this. reborrow ( ) . resolve_ident_in_scope (
440460 ident,
441- orig_ident . span ,
461+ orig_ident_span ,
442462 ns,
443463 scope,
444464 use_prelude,
@@ -472,7 +492,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
472492 if let Some ( & ( innermost_decl, _) ) = innermost_results. first ( ) {
473493 // Found another solution, if the first one was "weak", report an error.
474494 if this. get_mut ( ) . maybe_push_ambiguity (
475- orig_ident,
495+ ident,
496+ orig_ident_span,
476497 ns,
477498 scope_set,
478499 parent_scope,
@@ -695,8 +716,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
695716 Scope :: StdLibPrelude => {
696717 let mut result = Err ( Determinacy :: Determined ) ;
697718 if let Some ( prelude) = self . prelude
698- && let Ok ( decl) = self . reborrow ( ) . resolve_ident_in_scope_set (
699- ident. orig ( orig_ident_span. with_ctxt ( * ident. ctxt ) ) ,
719+ && let Ok ( decl) = self . reborrow ( ) . resolve_ident_in_scope_set_inner (
720+ ident,
721+ orig_ident_span,
700722 ScopeSet :: Module ( ns, prelude) ,
701723 parent_scope,
702724 None ,
@@ -749,7 +771,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
749771
750772 fn maybe_push_ambiguity (
751773 & mut self ,
752- orig_ident : Ident ,
774+ ident : IdentKey ,
775+ orig_ident_span : Span ,
753776 ns : Namespace ,
754777 scope_set : ScopeSet < ' ra > ,
755778 parent_scope : & ParentScope < ' ra > ,
@@ -775,7 +798,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
775798 } else if innermost_res == derive_helper_compat {
776799 Some ( AmbiguityKind :: DeriveHelper )
777800 } else if res == derive_helper_compat && innermost_res != derive_helper {
778- span_bug ! ( orig_ident . span , "impossible inner resolution kind" )
801+ span_bug ! ( orig_ident_span , "impossible inner resolution kind" )
779802 } else if matches ! ( innermost_scope, Scope :: MacroRules ( _) )
780803 && matches ! ( scope, Scope :: ModuleNonGlobs ( ..) | Scope :: ModuleGlobs ( ..) )
781804 && !self . disambiguate_macro_rules_vs_modularized ( innermost_decl, decl)
@@ -790,7 +813,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
790813 // we visit all macro_rules scopes (e.g. textual scope macros)
791814 // before we visit any modules (e.g. path-based scope macros)
792815 span_bug ! (
793- orig_ident . span ,
816+ orig_ident_span ,
794817 "ambiguous scoped macro resolutions with path-based \
795818 scope resolution as first candidate"
796819 )
@@ -839,8 +862,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
839862 } else {
840863 // Turn ambiguity errors for core vs std panic into warnings.
841864 // FIXME: Remove with lang team approval.
842- let is_issue_147319_hack = orig_ident . span . edition ( ) <= Edition :: Edition2024
843- && matches ! ( orig_ident . name, sym:: panic)
865+ let is_issue_147319_hack = orig_ident_span . edition ( ) <= Edition :: Edition2024
866+ && matches ! ( ident . name, sym:: panic)
844867 && matches ! ( scope, Scope :: StdLibPrelude )
845868 && matches ! ( innermost_scope, Scope :: ModuleGlobs ( _, _) )
846869 && ( ( self . is_specific_builtin_macro ( res, sym:: std_panic)
@@ -852,7 +875,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
852875
853876 self . ambiguity_errors . push ( AmbiguityError {
854877 kind,
855- ident : orig_ident ,
878+ ident : ident . orig ( orig_ident_span ) ,
856879 b1 : innermost_decl,
857880 b2 : decl,
858881 scope1 : innermost_scope,
@@ -880,46 +903,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
880903
881904 #[ instrument( level = "debug" , skip( self ) ) ]
882905 pub ( crate ) fn resolve_ident_in_module < ' r > (
883- self : CmResolver < ' r , ' ra , ' tcx > ,
884- module : ModuleOrUniformRoot < ' ra > ,
885- mut ident : Ident ,
886- ns : Namespace ,
887- parent_scope : & ParentScope < ' ra > ,
888- finalize : Option < Finalize > ,
889- ignore_decl : Option < Decl < ' ra > > ,
890- ignore_import : Option < Import < ' ra > > ,
891- ) -> Result < Decl < ' ra > , Determinacy > {
892- let tmp_parent_scope;
893- let mut adjusted_parent_scope = parent_scope;
894- match module {
895- ModuleOrUniformRoot :: Module ( m) => {
896- if let Some ( def) = ident. span . normalize_to_macros_2_0_and_adjust ( m. expansion ) {
897- tmp_parent_scope =
898- ParentScope { module : self . expn_def_scope ( def) , ..* parent_scope } ;
899- adjusted_parent_scope = & tmp_parent_scope;
900- }
901- }
902- ModuleOrUniformRoot :: ExternPrelude => {
903- ident. span . normalize_to_macros_2_0_and_adjust ( ExpnId :: root ( ) ) ;
904- }
905- ModuleOrUniformRoot :: ModuleAndExternPrelude ( ..) | ModuleOrUniformRoot :: CurrentScope => {
906- // No adjustments
907- }
908- }
909- self . resolve_ident_in_virt_module_unadjusted (
910- module,
911- ident,
912- ns,
913- adjusted_parent_scope,
914- finalize,
915- ignore_decl,
916- ignore_import,
917- )
918- }
919-
920- /// Attempts to resolve `ident` in namespace `ns` of `module`.
921- #[ instrument( level = "debug" , skip( self ) ) ]
922- fn resolve_ident_in_virt_module_unadjusted < ' r > (
923906 self : CmResolver < ' r , ' ra , ' tcx > ,
924907 module : ModuleOrUniformRoot < ' ra > ,
925908 ident : Ident ,
@@ -930,14 +913,22 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
930913 ignore_import : Option < Import < ' ra > > ,
931914 ) -> Result < Decl < ' ra > , Determinacy > {
932915 match module {
933- ModuleOrUniformRoot :: Module ( module) => self . resolve_ident_in_scope_set (
934- ident,
935- ScopeSet :: Module ( ns, module) ,
936- parent_scope,
937- finalize,
938- ignore_decl,
939- ignore_import,
940- ) ,
916+ ModuleOrUniformRoot :: Module ( module) => {
917+ let ( ident_key, def) = IdentKey :: new_adjusted ( ident, module. expansion ) ;
918+ let adjusted_parent_scope = match def {
919+ Some ( def) => ParentScope { module : self . expn_def_scope ( def) , ..* parent_scope } ,
920+ None => * parent_scope,
921+ } ;
922+ self . resolve_ident_in_scope_set_inner (
923+ ident_key,
924+ ident. span ,
925+ ScopeSet :: Module ( ns, module) ,
926+ & adjusted_parent_scope,
927+ finalize,
928+ ignore_decl,
929+ ignore_import,
930+ )
931+ }
941932 ModuleOrUniformRoot :: ModuleAndExternPrelude ( module) => self . resolve_ident_in_scope_set (
942933 ident,
943934 ScopeSet :: ModuleAndExternPrelude ( ns, module) ,
@@ -950,8 +941,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
950941 if ns != TypeNS {
951942 Err ( Determined )
952943 } else {
953- self . resolve_ident_in_scope_set (
954- ident,
944+ self . resolve_ident_in_scope_set_inner (
945+ IdentKey :: new_adjusted ( ident, ExpnId :: root ( ) ) . 0 ,
946+ ident. span ,
955947 ScopeSet :: ExternPrelude ,
956948 parent_scope,
957949 finalize,
@@ -1145,8 +1137,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11451137 None => return Err ( ControlFlow :: Continue ( Undetermined ) ) ,
11461138 } ;
11471139 let tmp_parent_scope;
1148- let ( mut adjusted_parent_scope, mut ctxt) = ( parent_scope, * ident. ctxt ) ;
1149- match ctxt. glob_adjust ( module. expansion , glob_import. span ) {
1140+ let ( mut adjusted_parent_scope, mut adjusted_ident) = ( parent_scope, ident) ;
1141+ match adjusted_ident
1142+ . ctxt
1143+ . update_unchecked ( |ctxt| ctxt. glob_adjust ( module. expansion , glob_import. span ) )
1144+ {
11501145 Some ( Some ( def) ) => {
11511146 tmp_parent_scope =
11521147 ParentScope { module : self . expn_def_scope ( def) , ..* parent_scope } ;
@@ -1155,8 +1150,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11551150 Some ( None ) => { }
11561151 None => continue ,
11571152 } ;
1158- let result = self . reborrow ( ) . resolve_ident_in_scope_set (
1159- ident. orig ( orig_ident_span. with_ctxt ( ctxt) ) ,
1153+ let result = self . reborrow ( ) . resolve_ident_in_scope_set_inner (
1154+ adjusted_ident,
1155+ orig_ident_span,
11601156 ScopeSet :: Module ( ns, module) ,
11611157 adjusted_parent_scope,
11621158 None ,
0 commit comments