@@ -309,7 +309,7 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
309
309
None
310
310
}
311
311
312
- fn resolve_macro_invocation ( & mut self , invoc : & Invocation , scope : Mark , force : bool )
312
+ fn resolve_macro_invocation ( & mut self , invoc : & Invocation , invoc_id : Mark , force : bool )
313
313
-> Result < Option < Lrc < SyntaxExtension > > , Determinacy > {
314
314
let ( path, kind, derives_in_scope) = match invoc. kind {
315
315
InvocationKind :: Attr { attr : None , .. } =>
@@ -322,7 +322,7 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
322
322
( path, MacroKind :: Derive , & [ ] [ ..] ) ,
323
323
} ;
324
324
325
- let ( def, ext) = self . resolve_macro_to_def ( path, kind, scope , derives_in_scope, force) ?;
325
+ let ( def, ext) = self . resolve_macro_to_def ( path, kind, invoc_id , derives_in_scope, force) ?;
326
326
327
327
if let Def :: Macro ( def_id, _) = def {
328
328
self . macro_defs . insert ( invoc. expansion_data . mark , def_id) ;
@@ -337,10 +337,10 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
337
337
Ok ( Some ( ext) )
338
338
}
339
339
340
- fn resolve_macro_path ( & mut self , path : & ast:: Path , kind : MacroKind , scope : Mark ,
340
+ fn resolve_macro_path ( & mut self , path : & ast:: Path , kind : MacroKind , invoc_id : Mark ,
341
341
derives_in_scope : & [ ast:: Path ] , force : bool )
342
342
-> Result < Lrc < SyntaxExtension > , Determinacy > {
343
- Ok ( self . resolve_macro_to_def ( path, kind, scope , derives_in_scope, force) ?. 1 )
343
+ Ok ( self . resolve_macro_to_def ( path, kind, invoc_id , derives_in_scope, force) ?. 1 )
344
344
}
345
345
346
346
fn check_unused_macros ( & self ) {
@@ -362,10 +362,10 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
362
362
}
363
363
364
364
impl < ' a , ' cl > Resolver < ' a , ' cl > {
365
- fn resolve_macro_to_def ( & mut self , path : & ast:: Path , kind : MacroKind , scope : Mark ,
365
+ fn resolve_macro_to_def ( & mut self , path : & ast:: Path , kind : MacroKind , invoc_id : Mark ,
366
366
derives_in_scope : & [ ast:: Path ] , force : bool )
367
367
-> Result < ( Def , Lrc < SyntaxExtension > ) , Determinacy > {
368
- let def = self . resolve_macro_to_def_inner ( path, kind, scope , derives_in_scope, force) ;
368
+ let def = self . resolve_macro_to_def_inner ( path, kind, invoc_id , derives_in_scope, force) ;
369
369
370
370
// Report errors and enforce feature gates for the resolved macro.
371
371
if def != Err ( Determinacy :: Undetermined ) {
@@ -435,8 +435,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
435
435
let ast:: Path { ref segments, span } = * path;
436
436
let mut path: Vec < _ > = segments. iter ( ) . map ( |seg| seg. ident ) . collect ( ) ;
437
437
let invocation = self . invocations [ & invoc_id] ;
438
- let module = invocation. module . get ( ) ;
439
- self . current_module = if module. is_trait ( ) { module. parent . unwrap ( ) } else { module } ;
438
+ let parent_expansion = invoc_id. parent ( ) ;
439
+ let parent_legacy_scope = invocation. parent_legacy_scope . get ( ) ;
440
+ self . current_module = invocation. module . get ( ) . nearest_item_scope ( ) ;
440
441
441
442
// Possibly apply the macro helper hack
442
443
if kind == MacroKind :: Bang && path. len ( ) == 1 &&
@@ -446,8 +447,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
446
447
}
447
448
448
449
if path. len ( ) > 1 {
449
- let def = match self . resolve_path_with_invoc_id ( None , & path, Some ( MacroNS ) , invoc_id,
450
- false , span, CrateLint :: No ) {
450
+ let def = match self . resolve_path_with_parent_expansion ( None , & path, Some ( MacroNS ) ,
451
+ parent_expansion, false , span,
452
+ CrateLint :: No ) {
451
453
PathResult :: NonModule ( path_res) => match path_res. base_def ( ) {
452
454
Def :: Err => Err ( Determinacy :: Determined ) ,
453
455
def @ _ => {
@@ -467,19 +469,19 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
467
469
Err ( Determinacy :: Determined )
468
470
} ,
469
471
} ;
470
- self . current_module . nearest_item_scope ( ) . macro_resolutions . borrow_mut ( )
472
+ self . current_module . macro_resolutions . borrow_mut ( )
471
473
. push ( ( path. into_boxed_slice ( ) , span) ) ;
472
474
return def;
473
475
}
474
476
475
477
let legacy_resolution = self . resolve_legacy_scope (
476
- path[ 0 ] , invoc_id , invocation . parent_legacy_scope . get ( ) , false
478
+ path[ 0 ] , parent_expansion , parent_legacy_scope, false
477
479
) ;
478
480
let result = if let Some ( legacy_binding) = legacy_resolution {
479
481
Ok ( legacy_binding. def ( ) )
480
482
} else {
481
- match self . resolve_lexical_macro_path_segment ( path[ 0 ] , MacroNS , invoc_id , false , force ,
482
- kind == MacroKind :: Attr , span) {
483
+ match self . resolve_lexical_macro_path_segment ( path[ 0 ] , MacroNS , parent_expansion , false ,
484
+ force , kind == MacroKind :: Attr , span) {
483
485
Ok ( ( binding, _) ) => Ok ( binding. def_ignoring_ambiguity ( ) ) ,
484
486
Err ( Determinacy :: Undetermined ) => return Err ( Determinacy :: Undetermined ) ,
485
487
Err ( Determinacy :: Determined ) => {
@@ -489,8 +491,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
489
491
}
490
492
} ;
491
493
492
- self . current_module . nearest_item_scope ( ) . legacy_macro_resolutions . borrow_mut ( )
493
- . push ( ( invoc_id , path[ 0 ] , kind, result. ok ( ) ) ) ;
494
+ self . current_module . legacy_macro_resolutions . borrow_mut ( )
495
+ . push ( ( path[ 0 ] , kind, parent_expansion , parent_legacy_scope , result. ok ( ) ) ) ;
494
496
495
497
if let Ok ( Def :: NonMacroAttr ( NonMacroAttrKind :: Custom ) ) = result { } else {
496
498
return result;
@@ -537,7 +539,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
537
539
& mut self ,
538
540
mut ident : Ident ,
539
541
ns : Namespace ,
540
- invoc_id : Mark ,
542
+ parent_expansion : Mark ,
541
543
record_used : bool ,
542
544
force : bool ,
543
545
is_attr : bool ,
@@ -732,7 +734,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
732
734
// Found another solution, if the first one was "weak", report an error.
733
735
if result. 0 . def ( ) != innermost_result. 0 . def ( ) &&
734
736
( innermost_result. 0 . is_glob_import ( ) ||
735
- innermost_result. 0 . may_appear_after ( invoc_id , result. 0 ) ) {
737
+ innermost_result. 0 . may_appear_after ( parent_expansion , result. 0 ) ) {
736
738
self . ambiguity_errors . push ( AmbiguityError {
737
739
span : path_span,
738
740
name : ident. name ,
@@ -777,8 +779,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
777
779
778
780
fn resolve_legacy_scope ( & mut self ,
779
781
ident : Ident ,
780
- invoc_id : Mark ,
781
- invoc_parent_legacy_scope : LegacyScope < ' a > ,
782
+ parent_expansion : Mark ,
783
+ parent_legacy_scope : LegacyScope < ' a > ,
782
784
record_used : bool )
783
785
-> Option < & ' a NameBinding < ' a > > {
784
786
let ident = ident. modern ( ) ;
@@ -797,7 +799,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
797
799
let mut innermost_result: Option < & NameBinding > = None ;
798
800
799
801
// Go through all the scopes and try to resolve the name.
800
- let mut where_to_resolve = invoc_parent_legacy_scope ;
802
+ let mut where_to_resolve = parent_legacy_scope ;
801
803
loop {
802
804
let result = match where_to_resolve {
803
805
LegacyScope :: Binding ( legacy_binding) if ident == legacy_binding. ident =>
@@ -825,7 +827,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
825
827
if let Some ( innermost_result) = innermost_result {
826
828
// Found another solution, if the first one was "weak", report an error.
827
829
if result. def ( ) != innermost_result. def ( ) &&
828
- innermost_result. may_appear_after ( invoc_id , result) {
830
+ innermost_result. may_appear_after ( parent_expansion , result) {
829
831
self . ambiguity_errors . push ( AmbiguityError {
830
832
span : ident. span ,
831
833
name : ident. name ,
@@ -863,14 +865,14 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
863
865
}
864
866
}
865
867
866
- for & ( invoc_id, ident, kind, def) in module. legacy_macro_resolutions . borrow ( ) . iter ( ) {
868
+ for & ( ident, kind, parent_expansion, parent_legacy_scope, def)
869
+ in module. legacy_macro_resolutions . borrow ( ) . iter ( ) {
867
870
let span = ident. span ;
868
- let invocation = self . invocations [ & invoc_id] ;
869
871
let legacy_resolution = self . resolve_legacy_scope (
870
- ident, invoc_id , invocation . parent_legacy_scope . get ( ) , true
872
+ ident, parent_expansion , parent_legacy_scope, true
871
873
) ;
872
874
let resolution = self . resolve_lexical_macro_path_segment (
873
- ident, MacroNS , invoc_id , true , true , kind == MacroKind :: Attr , span
875
+ ident, MacroNS , parent_expansion , true , true , kind == MacroKind :: Attr , span
874
876
) ;
875
877
876
878
let check_consistency = |this : & Self , new_def : Def | {
@@ -904,12 +906,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
904
906
err. emit ( ) ;
905
907
} ,
906
908
( Some ( legacy_binding) , Ok ( ( binding, FromPrelude ( from_prelude) ) ) )
907
- if !from_prelude || legacy_binding. may_appear_after ( invoc_id , binding ) => {
908
- if legacy_binding . def_ignoring_ambiguity ( ) != binding . def_ignoring_ambiguity ( ) {
909
- self . report_ambiguity_error ( ident . name , span , legacy_binding, binding) ;
910
- }
909
+ if legacy_binding. def ( ) != binding . def_ignoring_ambiguity ( ) &&
910
+ ( !from_prelude ||
911
+ legacy_binding. may_appear_after ( parent_expansion , binding) ) => {
912
+ self . report_ambiguity_error ( ident . name , span , legacy_binding , binding ) ;
911
913
} ,
912
914
// OK, non-macro-expanded legacy wins over prelude even if defs are different
915
+ // Also, legacy and modern can co-exist if their defs are same
913
916
( Some ( legacy_binding) , Ok ( _) ) |
914
917
// OK, unambiguous resolution
915
918
( Some ( legacy_binding) , Err ( _) ) => {
0 commit comments