@@ -431,12 +431,12 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
431
431
Ok ( ( def, self . get_macro ( def) ) )
432
432
}
433
433
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 ,
435
435
derives_in_scope : & [ ast:: Path ] , force : bool )
436
436
-> Result < Def , Determinacy > {
437
437
let ast:: Path { ref segments, span } = * path;
438
438
let mut path: Vec < _ > = segments. iter ( ) . map ( |seg| seg. ident ) . collect ( ) ;
439
- let invocation = self . invocations [ & scope ] ;
439
+ let invocation = self . invocations [ & invoc_id ] ;
440
440
let module = invocation. module . get ( ) ;
441
441
self . current_module = if module. is_trait ( ) { module. parent . unwrap ( ) } else { module } ;
442
442
@@ -448,8 +448,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
448
448
}
449
449
450
450
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 ) {
453
453
PathResult :: NonModule ( path_res) => match path_res. base_def ( ) {
454
454
Def :: Err => Err ( Determinacy :: Determined ) ,
455
455
def @ _ => {
@@ -480,11 +480,12 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
480
480
}
481
481
}
482
482
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 ) ;
484
485
let result = if let Some ( legacy_binding) = legacy_resolution {
485
486
Ok ( legacy_binding. def ( ) )
486
487
} 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,
488
489
kind == MacroKind :: Attr , span) {
489
490
Ok ( ( binding, _) ) => Ok ( binding. def_ignoring_ambiguity ( ) ) ,
490
491
Err ( Determinacy :: Undetermined ) => return Err ( Determinacy :: Undetermined ) ,
@@ -496,7 +497,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
496
497
} ;
497
498
498
499
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 ( ) ) ) ;
500
501
501
502
if let Ok ( Def :: NonMacroAttr ( NonMacroAttrKind :: Custom ) ) = result { } else {
502
503
return result;
@@ -515,7 +516,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
515
516
enum ConvertToDeriveHelper { Yes , No , DontKnow }
516
517
let mut convert_to_derive_helper = ConvertToDeriveHelper :: No ;
517
518
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) {
519
520
Ok ( ext) => if let SyntaxExtension :: ProcMacroDerive ( _, ref inert_attrs, _) = * ext {
520
521
if inert_attrs. contains ( & path[ 0 ] . name ) {
521
522
convert_to_derive_helper = ConvertToDeriveHelper :: Yes ;
@@ -543,10 +544,11 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
543
544
& mut self ,
544
545
mut ident : Ident ,
545
546
ns : Namespace ,
547
+ invoc_id : Mark ,
546
548
record_used : bool ,
547
549
force : bool ,
548
550
is_attr : bool ,
549
- path_span : Span
551
+ path_span : Span ,
550
552
) -> Result < ( & ' a NameBinding < ' a > , FromPrelude ) , Determinacy > {
551
553
// General principles:
552
554
// 1. Not controlled (user-defined) names should have higher priority than controlled names
@@ -737,7 +739,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
737
739
// Found another solution, if the first one was "weak", report an error.
738
740
if result. 0 . def ( ) != innermost_result. 0 . def ( ) &&
739
741
( innermost_result. 0 . is_glob_import ( ) ||
740
- innermost_result. 0 . expansion != Mark :: root ( ) ) {
742
+ innermost_result. 0 . may_appear_after ( invoc_id , result . 0 ) ) {
741
743
self . ambiguity_errors . push ( AmbiguityError {
742
744
span : path_span,
743
745
name : ident. name ,
@@ -781,8 +783,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
781
783
}
782
784
783
785
fn resolve_legacy_scope ( & mut self ,
784
- invocation_legacy_scope : & ' a Cell < LegacyScope < ' a > > ,
785
786
ident : Ident ,
787
+ invoc_id : Mark ,
788
+ invoc_parent_legacy_scope : & ' a Cell < LegacyScope < ' a > > ,
786
789
record_used : bool )
787
790
-> Option < & ' a NameBinding < ' a > > {
788
791
let ident = ident. modern ( ) ;
@@ -801,7 +804,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
801
804
let mut innermost_result: Option < & NameBinding > = None ;
802
805
803
806
// 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 ;
805
808
loop {
806
809
let result = match where_to_resolve. get ( ) {
807
810
LegacyScope :: Binding ( legacy_binding) if ident == legacy_binding. ident =>
@@ -837,7 +840,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
837
840
if let Some ( innermost_result) = innermost_result {
838
841
// Found another solution, if the first one was "weak", report an error.
839
842
if result. def ( ) != innermost_result. def ( ) &&
840
- innermost_result. expansion != Mark :: root ( ) {
843
+ innermost_result. may_appear_after ( invoc_id , result ) {
841
844
self . ambiguity_errors . push ( AmbiguityError {
842
845
span : ident. span ,
843
846
name : ident. name ,
@@ -875,12 +878,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
875
878
}
876
879
}
877
880
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 ( ) {
879
882
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
+ ) ;
884
888
885
889
let check_consistency = |this : & Self , new_def : Def | {
886
890
if let Some ( def) = def {
@@ -913,7 +917,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
913
917
err. emit ( ) ;
914
918
} ,
915
919
( 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 ) => {
917
921
if legacy_binding. def_ignoring_ambiguity ( ) != binding. def_ignoring_ambiguity ( ) {
918
922
self . report_ambiguity_error ( ident. name , span, legacy_binding, binding) ;
919
923
}
0 commit comments