@@ -414,12 +414,12 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
414
414
Ok ( ( def, self . get_macro ( def) ) )
415
415
}
416
416
417
- pub fn resolve_macro_to_def_inner ( & mut self , path : & ast:: Path , kind : MacroKind , scope : Mark ,
417
+ pub fn resolve_macro_to_def_inner ( & mut self , path : & ast:: Path , kind : MacroKind , invoc_id : Mark ,
418
418
derives_in_scope : & [ ast:: Path ] , force : bool )
419
419
-> Result < Def , Determinacy > {
420
420
let ast:: Path { ref segments, span } = * path;
421
421
let mut path: Vec < _ > = segments. iter ( ) . map ( |seg| seg. ident ) . collect ( ) ;
422
- let invocation = self . invocations [ & scope ] ;
422
+ let invocation = self . invocations [ & invoc_id ] ;
423
423
let module = invocation. module . get ( ) ;
424
424
self . current_module = if module. is_trait ( ) { module. parent . unwrap ( ) } else { module } ;
425
425
@@ -431,8 +431,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
431
431
}
432
432
433
433
if path. len ( ) > 1 {
434
- let res = self . resolve_path ( None , & path, Some ( MacroNS ) , false , span , CrateLint :: No ) ;
435
- let def = match res {
434
+ let def = match self . resolve_path_with_invoc_id ( None , & path, Some ( MacroNS ) , invoc_id ,
435
+ false , span , CrateLint :: No ) {
436
436
PathResult :: NonModule ( path_res) => match path_res. base_def ( ) {
437
437
Def :: Err => Err ( Determinacy :: Determined ) ,
438
438
def @ _ => {
@@ -457,11 +457,12 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
457
457
return def;
458
458
}
459
459
460
- let legacy_resolution = self . resolve_legacy_scope ( & invocation. legacy_scope , path[ 0 ] , false ) ;
460
+ let legacy_resolution =
461
+ self . resolve_legacy_scope ( path[ 0 ] , invoc_id, & invocation. legacy_scope , false ) ;
461
462
let result = if let Some ( legacy_binding) = legacy_resolution {
462
463
Ok ( legacy_binding. def ( ) )
463
464
} else {
464
- match self . resolve_lexical_macro_path_segment ( path[ 0 ] , MacroNS , false , force,
465
+ match self . resolve_lexical_macro_path_segment ( path[ 0 ] , MacroNS , invoc_id , false , force,
465
466
kind == MacroKind :: Attr , span) {
466
467
Ok ( ( binding, _) ) => Ok ( binding. def_ignoring_ambiguity ( ) ) ,
467
468
Err ( Determinacy :: Undetermined ) => return Err ( Determinacy :: Undetermined ) ,
@@ -473,7 +474,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
473
474
} ;
474
475
475
476
self . current_module . nearest_item_scope ( ) . legacy_macro_resolutions . borrow_mut ( )
476
- . push ( ( scope , path[ 0 ] , kind, result. ok ( ) ) ) ;
477
+ . push ( ( invoc_id , path[ 0 ] , kind, result. ok ( ) ) ) ;
477
478
478
479
if let Ok ( Def :: NonMacroAttr ( NonMacroAttrKind :: Custom ) ) = result { } else {
479
480
return result;
@@ -492,7 +493,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
492
493
enum ConvertToDeriveHelper { Yes , No , DontKnow }
493
494
let mut convert_to_derive_helper = ConvertToDeriveHelper :: No ;
494
495
for derive in derives_in_scope {
495
- match self . resolve_macro_path ( derive, MacroKind :: Derive , scope , & [ ] , force) {
496
+ match self . resolve_macro_path ( derive, MacroKind :: Derive , invoc_id , & [ ] , force) {
496
497
Ok ( ext) => if let SyntaxExtension :: ProcMacroDerive ( _, ref inert_attrs, _) = * ext {
497
498
if inert_attrs. contains ( & path[ 0 ] . name ) {
498
499
convert_to_derive_helper = ConvertToDeriveHelper :: Yes ;
@@ -520,10 +521,11 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
520
521
& mut self ,
521
522
mut ident : Ident ,
522
523
ns : Namespace ,
524
+ invoc_id : Mark ,
523
525
record_used : bool ,
524
526
force : bool ,
525
527
is_attr : bool ,
526
- path_span : Span
528
+ path_span : Span ,
527
529
) -> Result < ( & ' a NameBinding < ' a > , FromPrelude ) , Determinacy > {
528
530
// General principles:
529
531
// 1. Not controlled (user-defined) names should have higher priority than controlled names
@@ -714,7 +716,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
714
716
// Found another solution, if the first one was "weak", report an error.
715
717
if result. 0 . def ( ) != innermost_result. 0 . def ( ) &&
716
718
( innermost_result. 0 . is_glob_import ( ) ||
717
- innermost_result. 0 . expansion != Mark :: root ( ) ) {
719
+ innermost_result. 0 . may_appear_after ( invoc_id , result . 0 ) ) {
718
720
self . ambiguity_errors . push ( AmbiguityError {
719
721
span : path_span,
720
722
name : ident. name ,
@@ -758,8 +760,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
758
760
}
759
761
760
762
fn resolve_legacy_scope ( & mut self ,
761
- invocation_legacy_scope : & ' a Cell < LegacyScope < ' a > > ,
762
763
ident : Ident ,
764
+ invoc_id : Mark ,
765
+ invoc_parent_legacy_scope : & ' a Cell < LegacyScope < ' a > > ,
763
766
record_used : bool )
764
767
-> Option < & ' a NameBinding < ' a > > {
765
768
let ident = ident. modern ( ) ;
@@ -778,7 +781,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
778
781
let mut innermost_result: Option < & NameBinding > = None ;
779
782
780
783
// Go through all the scopes and try to resolve the name.
781
- let mut where_to_resolve = invocation_legacy_scope ;
784
+ let mut where_to_resolve = invoc_parent_legacy_scope ;
782
785
loop {
783
786
let result = match where_to_resolve. get ( ) {
784
787
LegacyScope :: Binding ( legacy_binding) if ident == legacy_binding. ident =>
@@ -814,7 +817,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
814
817
if let Some ( innermost_result) = innermost_result {
815
818
// Found another solution, if the first one was "weak", report an error.
816
819
if result. def ( ) != innermost_result. def ( ) &&
817
- innermost_result. expansion != Mark :: root ( ) {
820
+ innermost_result. may_appear_after ( invoc_id , result ) {
818
821
self . ambiguity_errors . push ( AmbiguityError {
819
822
span : ident. span ,
820
823
name : ident. name ,
@@ -852,12 +855,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
852
855
}
853
856
}
854
857
855
- for & ( mark , ident, kind, def) in module. legacy_macro_resolutions . borrow ( ) . iter ( ) {
858
+ for & ( invoc_id , ident, kind, def) in module. legacy_macro_resolutions . borrow ( ) . iter ( ) {
856
859
let span = ident. span ;
857
- let legacy_scope = & self . invocations [ & mark] . legacy_scope ;
858
- let legacy_resolution = self . resolve_legacy_scope ( legacy_scope, ident, true ) ;
859
- let resolution = self . resolve_lexical_macro_path_segment ( ident, MacroNS , true , true ,
860
- kind == MacroKind :: Attr , span) ;
860
+ let legacy_scope = & self . invocations [ & invoc_id] . legacy_scope ;
861
+ let legacy_resolution = self . resolve_legacy_scope ( ident, invoc_id, legacy_scope, true ) ;
862
+ let resolution = self . resolve_lexical_macro_path_segment (
863
+ ident, MacroNS , invoc_id, true , true , kind == MacroKind :: Attr , span
864
+ ) ;
861
865
862
866
let check_consistency = |this : & Self , new_def : Def | {
863
867
if let Some ( def) = def {
@@ -890,7 +894,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
890
894
err. emit ( ) ;
891
895
} ,
892
896
( Some ( legacy_binding) , Ok ( ( binding, FromPrelude ( from_prelude) ) ) )
893
- if !from_prelude || legacy_binding. expansion != Mark :: root ( ) => {
897
+ if !from_prelude || legacy_binding. may_appear_after ( invoc_id , binding ) => {
894
898
if legacy_binding. def_ignoring_ambiguity ( ) != binding. def_ignoring_ambiguity ( ) {
895
899
self . report_ambiguity_error ( ident. name , span, legacy_binding, binding) ;
896
900
}
0 commit comments