@@ -431,12 +431,12 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
431431 Ok ( ( def, self . get_macro ( def) ) )
432432 }
433433
434- pub fn resolve_macro_to_def_inner ( & mut self , path : & ast:: Path , kind : MacroKind , scope : Mark ,
434+ pub fn resolve_macro_to_def_inner ( & mut self , path : & ast:: Path , kind : MacroKind , invoc_id : Mark ,
435435 derives_in_scope : & [ ast:: Path ] , force : bool )
436436 -> Result < Def , Determinacy > {
437437 let ast:: Path { ref segments, span } = * path;
438438 let mut path: Vec < _ > = segments. iter ( ) . map ( |seg| seg. ident ) . collect ( ) ;
439- let invocation = self . invocations [ & scope ] ;
439+ let invocation = self . invocations [ & invoc_id ] ;
440440 let module = invocation. module . get ( ) ;
441441 self . current_module = if module. is_trait ( ) { module. parent . unwrap ( ) } else { module } ;
442442
@@ -448,8 +448,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
448448 }
449449
450450 if path. len ( ) > 1 {
451- let res = self . resolve_path ( None , & path, Some ( MacroNS ) , false , span , CrateLint :: No ) ;
452- let def = match res {
451+ let def = match self . resolve_path_with_invoc_id ( None , & path, Some ( MacroNS ) , invoc_id ,
452+ false , span , CrateLint :: No ) {
453453 PathResult :: NonModule ( path_res) => match path_res. base_def ( ) {
454454 Def :: Err => Err ( Determinacy :: Determined ) ,
455455 def @ _ => {
@@ -480,11 +480,12 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
480480 }
481481 }
482482
483- let legacy_resolution = self . resolve_legacy_scope ( & invocation. legacy_scope , path[ 0 ] , false ) ;
483+ let legacy_resolution =
484+ self . resolve_legacy_scope ( path[ 0 ] , invoc_id, & invocation. legacy_scope , false ) ;
484485 let result = if let Some ( legacy_binding) = legacy_resolution {
485486 Ok ( legacy_binding. def ( ) )
486487 } else {
487- match self . resolve_lexical_macro_path_segment ( path[ 0 ] , MacroNS , false , force,
488+ match self . resolve_lexical_macro_path_segment ( path[ 0 ] , MacroNS , invoc_id , false , force,
488489 kind == MacroKind :: Attr , span) {
489490 Ok ( ( binding, _) ) => Ok ( binding. def_ignoring_ambiguity ( ) ) ,
490491 Err ( Determinacy :: Undetermined ) => return Err ( Determinacy :: Undetermined ) ,
@@ -496,7 +497,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
496497 } ;
497498
498499 self . current_module . nearest_item_scope ( ) . legacy_macro_resolutions . borrow_mut ( )
499- . push ( ( scope , path[ 0 ] , kind, result. ok ( ) ) ) ;
500+ . push ( ( invoc_id , path[ 0 ] , kind, result. ok ( ) ) ) ;
500501
501502 if let Ok ( Def :: NonMacroAttr ( NonMacroAttrKind :: Custom ) ) = result { } else {
502503 return result;
@@ -515,7 +516,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
515516 enum ConvertToDeriveHelper { Yes , No , DontKnow }
516517 let mut convert_to_derive_helper = ConvertToDeriveHelper :: No ;
517518 for derive in derives_in_scope {
518- match self . resolve_macro_path ( derive, MacroKind :: Derive , scope , & [ ] , force) {
519+ match self . resolve_macro_path ( derive, MacroKind :: Derive , invoc_id , & [ ] , force) {
519520 Ok ( ext) => if let SyntaxExtension :: ProcMacroDerive ( _, ref inert_attrs, _) = * ext {
520521 if inert_attrs. contains ( & path[ 0 ] . name ) {
521522 convert_to_derive_helper = ConvertToDeriveHelper :: Yes ;
@@ -543,10 +544,11 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
543544 & mut self ,
544545 mut ident : Ident ,
545546 ns : Namespace ,
547+ invoc_id : Mark ,
546548 record_used : bool ,
547549 force : bool ,
548550 is_attr : bool ,
549- path_span : Span
551+ path_span : Span ,
550552 ) -> Result < ( & ' a NameBinding < ' a > , FromPrelude ) , Determinacy > {
551553 // General principles:
552554 // 1. Not controlled (user-defined) names should have higher priority than controlled names
@@ -737,7 +739,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
737739 // Found another solution, if the first one was "weak", report an error.
738740 if result. 0 . def ( ) != innermost_result. 0 . def ( ) &&
739741 ( innermost_result. 0 . is_glob_import ( ) ||
740- innermost_result. 0 . expansion != Mark :: root ( ) ) {
742+ innermost_result. 0 . may_appear_after ( invoc_id , result . 0 ) ) {
741743 self . ambiguity_errors . push ( AmbiguityError {
742744 span : path_span,
743745 name : ident. name ,
@@ -781,8 +783,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
781783 }
782784
783785 fn resolve_legacy_scope ( & mut self ,
784- invocation_legacy_scope : & ' a Cell < LegacyScope < ' a > > ,
785786 ident : Ident ,
787+ invoc_id : Mark ,
788+ invoc_parent_legacy_scope : & ' a Cell < LegacyScope < ' a > > ,
786789 record_used : bool )
787790 -> Option < & ' a NameBinding < ' a > > {
788791 let ident = ident. modern ( ) ;
@@ -801,7 +804,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
801804 let mut innermost_result: Option < & NameBinding > = None ;
802805
803806 // Go through all the scopes and try to resolve the name.
804- let mut where_to_resolve = invocation_legacy_scope ;
807+ let mut where_to_resolve = invoc_parent_legacy_scope ;
805808 loop {
806809 let result = match where_to_resolve. get ( ) {
807810 LegacyScope :: Binding ( legacy_binding) if ident == legacy_binding. ident =>
@@ -837,7 +840,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
837840 if let Some ( innermost_result) = innermost_result {
838841 // Found another solution, if the first one was "weak", report an error.
839842 if result. def ( ) != innermost_result. def ( ) &&
840- innermost_result. expansion != Mark :: root ( ) {
843+ innermost_result. may_appear_after ( invoc_id , result ) {
841844 self . ambiguity_errors . push ( AmbiguityError {
842845 span : ident. span ,
843846 name : ident. name ,
@@ -875,12 +878,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
875878 }
876879 }
877880
878- for & ( mark , ident, kind, def) in module. legacy_macro_resolutions . borrow ( ) . iter ( ) {
881+ for & ( invoc_id , ident, kind, def) in module. legacy_macro_resolutions . borrow ( ) . iter ( ) {
879882 let span = ident. span ;
880- let legacy_scope = & self . invocations [ & mark] . legacy_scope ;
881- let legacy_resolution = self . resolve_legacy_scope ( legacy_scope, ident, true ) ;
882- let resolution = self . resolve_lexical_macro_path_segment ( ident, MacroNS , true , true ,
883- kind == MacroKind :: Attr , span) ;
883+ let legacy_scope = & self . invocations [ & invoc_id] . legacy_scope ;
884+ let legacy_resolution = self . resolve_legacy_scope ( ident, invoc_id, legacy_scope, true ) ;
885+ let resolution = self . resolve_lexical_macro_path_segment (
886+ ident, MacroNS , invoc_id, true , true , kind == MacroKind :: Attr , span
887+ ) ;
884888
885889 let check_consistency = |this : & Self , new_def : Def | {
886890 if let Some ( def) = def {
@@ -913,7 +917,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
913917 err. emit ( ) ;
914918 } ,
915919 ( Some ( legacy_binding) , Ok ( ( binding, FromPrelude ( from_prelude) ) ) )
916- if !from_prelude || legacy_binding. expansion != Mark :: root ( ) => {
920+ if !from_prelude || legacy_binding. may_appear_after ( invoc_id , binding ) => {
917921 if legacy_binding. def_ignoring_ambiguity ( ) != binding. def_ignoring_ambiguity ( ) {
918922 self . report_ambiguity_error ( ident. name , span, legacy_binding, binding) ;
919923 }
0 commit comments