@@ -313,7 +313,7 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
313
313
None
314
314
}
315
315
316
- fn resolve_macro_invocation ( & mut self , invoc : & Invocation , scope : Mark , force : bool )
316
+ fn resolve_macro_invocation ( & mut self , invoc : & Invocation , invoc_id : Mark , force : bool )
317
317
-> Result < Option < Lrc < SyntaxExtension > > , Determinacy > {
318
318
let ( path, kind, derives_in_scope) = match invoc. kind {
319
319
InvocationKind :: Attr { attr : None , .. } =>
@@ -326,7 +326,7 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
326
326
( path, MacroKind :: Derive , & [ ] [ ..] ) ,
327
327
} ;
328
328
329
- let ( def, ext) = self . resolve_macro_to_def ( path, kind, scope , derives_in_scope, force) ?;
329
+ let ( def, ext) = self . resolve_macro_to_def ( path, kind, invoc_id , derives_in_scope, force) ?;
330
330
331
331
if let Def :: Macro ( def_id, _) = def {
332
332
self . macro_defs . insert ( invoc. expansion_data . mark , def_id) ;
@@ -341,10 +341,10 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
341
341
Ok ( Some ( ext) )
342
342
}
343
343
344
- fn resolve_macro_path ( & mut self , path : & ast:: Path , kind : MacroKind , scope : Mark ,
344
+ fn resolve_macro_path ( & mut self , path : & ast:: Path , kind : MacroKind , invoc_id : Mark ,
345
345
derives_in_scope : & [ ast:: Path ] , force : bool )
346
346
-> Result < Lrc < SyntaxExtension > , Determinacy > {
347
- Ok ( self . resolve_macro_to_def ( path, kind, scope , derives_in_scope, force) ?. 1 )
347
+ Ok ( self . resolve_macro_to_def ( path, kind, invoc_id , derives_in_scope, force) ?. 1 )
348
348
}
349
349
350
350
fn check_unused_macros ( & self ) {
@@ -366,10 +366,10 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
366
366
}
367
367
368
368
impl < ' a , ' cl > Resolver < ' a , ' cl > {
369
- fn resolve_macro_to_def ( & mut self , path : & ast:: Path , kind : MacroKind , scope : Mark ,
369
+ fn resolve_macro_to_def ( & mut self , path : & ast:: Path , kind : MacroKind , invoc_id : Mark ,
370
370
derives_in_scope : & [ ast:: Path ] , force : bool )
371
371
-> Result < ( Def , Lrc < SyntaxExtension > ) , Determinacy > {
372
- let def = self . resolve_macro_to_def_inner ( path, kind, scope , derives_in_scope, force) ;
372
+ let def = self . resolve_macro_to_def_inner ( path, kind, invoc_id , derives_in_scope, force) ;
373
373
374
374
// Report errors and enforce feature gates for the resolved macro.
375
375
if def != Err ( Determinacy :: Undetermined ) {
@@ -439,8 +439,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
439
439
let ast:: Path { ref segments, span } = * path;
440
440
let mut path: Vec < _ > = segments. iter ( ) . map ( |seg| seg. ident ) . collect ( ) ;
441
441
let invocation = self . invocations [ & invoc_id] ;
442
- let module = invocation. module . get ( ) ;
443
- self . current_module = if module. is_trait ( ) { module. parent . unwrap ( ) } else { module } ;
442
+ let parent_expansion = invoc_id. parent ( ) ;
443
+ let parent_legacy_scope = invocation. parent_legacy_scope . get ( ) ;
444
+ self . current_module = invocation. module . get ( ) . nearest_item_scope ( ) ;
444
445
445
446
// Possibly apply the macro helper hack
446
447
if kind == MacroKind :: Bang && path. len ( ) == 1 &&
@@ -450,8 +451,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
450
451
}
451
452
452
453
if path. len ( ) > 1 {
453
- let def = match self . resolve_path_with_invoc_id ( None , & path, Some ( MacroNS ) , invoc_id,
454
- false , span, CrateLint :: No ) {
454
+ let def = match self . resolve_path_with_parent_expansion ( None , & path, Some ( MacroNS ) ,
455
+ parent_expansion, false , span,
456
+ CrateLint :: No ) {
455
457
PathResult :: NonModule ( path_res) => match path_res. base_def ( ) {
456
458
Def :: Err => Err ( Determinacy :: Determined ) ,
457
459
def @ _ => {
@@ -471,19 +473,19 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
471
473
Err ( Determinacy :: Determined )
472
474
} ,
473
475
} ;
474
- self . current_module . nearest_item_scope ( ) . macro_resolutions . borrow_mut ( )
476
+ self . current_module . macro_resolutions . borrow_mut ( )
475
477
. push ( ( path. into_boxed_slice ( ) , span) ) ;
476
478
return def;
477
479
}
478
480
479
481
let legacy_resolution = self . resolve_legacy_scope (
480
- path[ 0 ] , invoc_id , invocation . parent_legacy_scope . get ( ) , false , kind == MacroKind :: Attr
482
+ path[ 0 ] , parent_expansion , parent_legacy_scope, false , kind == MacroKind :: Attr
481
483
) ;
482
484
let result = if let Some ( legacy_binding) = legacy_resolution {
483
485
Ok ( legacy_binding. def ( ) )
484
486
} else {
485
- match self . resolve_lexical_macro_path_segment ( path[ 0 ] , MacroNS , invoc_id , false , force ,
486
- kind == MacroKind :: Attr , span) {
487
+ match self . resolve_lexical_macro_path_segment ( path[ 0 ] , MacroNS , parent_expansion , false ,
488
+ force , kind == MacroKind :: Attr , span) {
487
489
Ok ( ( binding, _) ) => Ok ( binding. def_ignoring_ambiguity ( ) ) ,
488
490
Err ( Determinacy :: Undetermined ) => return Err ( Determinacy :: Undetermined ) ,
489
491
Err ( Determinacy :: Determined ) => {
@@ -493,8 +495,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
493
495
}
494
496
} ;
495
497
496
- self . current_module . nearest_item_scope ( ) . legacy_macro_resolutions . borrow_mut ( )
497
- . push ( ( invoc_id , path[ 0 ] , kind, result. ok ( ) ) ) ;
498
+ self . current_module . legacy_macro_resolutions . borrow_mut ( )
499
+ . push ( ( path[ 0 ] , kind, parent_expansion , parent_legacy_scope , result. ok ( ) ) ) ;
498
500
499
501
if let Ok ( Def :: NonMacroAttr ( NonMacroAttrKind :: Custom ) ) = result { } else {
500
502
return result;
@@ -541,7 +543,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
541
543
& mut self ,
542
544
mut ident : Ident ,
543
545
ns : Namespace ,
544
- invoc_id : Mark ,
546
+ parent_expansion : Mark ,
545
547
record_used : bool ,
546
548
force : bool ,
547
549
is_attr : bool ,
@@ -754,7 +756,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
754
756
// Found another solution, if the first one was "weak", report an error.
755
757
if result. 0 . def ( ) != innermost_result. 0 . def ( ) &&
756
758
( innermost_result. 0 . is_glob_import ( ) ||
757
- innermost_result. 0 . may_appear_after ( invoc_id , result. 0 ) ) {
759
+ innermost_result. 0 . may_appear_after ( parent_expansion , result. 0 ) ) {
758
760
self . ambiguity_errors . push ( AmbiguityError {
759
761
ident,
760
762
b1 : innermost_result. 0 ,
@@ -798,8 +800,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
798
800
799
801
fn resolve_legacy_scope ( & mut self ,
800
802
ident : Ident ,
801
- invoc_id : Mark ,
802
- invoc_parent_legacy_scope : LegacyScope < ' a > ,
803
+ parent_expansion : Mark ,
804
+ parent_legacy_scope : LegacyScope < ' a > ,
803
805
record_used : bool ,
804
806
is_attr : bool )
805
807
-> Option < & ' a NameBinding < ' a > > {
@@ -826,7 +828,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
826
828
let mut innermost_result: Option < & NameBinding > = None ;
827
829
828
830
// Go through all the scopes and try to resolve the name.
829
- let mut where_to_resolve = invoc_parent_legacy_scope ;
831
+ let mut where_to_resolve = parent_legacy_scope ;
830
832
loop {
831
833
let result = match where_to_resolve {
832
834
LegacyScope :: Binding ( legacy_binding) if ident == legacy_binding. ident =>
@@ -854,7 +856,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
854
856
if let Some ( innermost_result) = innermost_result {
855
857
// Found another solution, if the first one was "weak", report an error.
856
858
if result. def ( ) != innermost_result. def ( ) &&
857
- innermost_result. may_appear_after ( invoc_id , result) {
859
+ innermost_result. may_appear_after ( parent_expansion , result) {
858
860
self . ambiguity_errors . push ( AmbiguityError {
859
861
ident,
860
862
b1 : innermost_result,
@@ -891,14 +893,14 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
891
893
}
892
894
}
893
895
894
- for & ( invoc_id, ident, kind, def) in module. legacy_macro_resolutions . borrow ( ) . iter ( ) {
896
+ for & ( ident, kind, parent_expansion, parent_legacy_scope, def)
897
+ in module. legacy_macro_resolutions . borrow ( ) . iter ( ) {
895
898
let span = ident. span ;
896
- let invocation = self . invocations [ & invoc_id] ;
897
899
let legacy_resolution = self . resolve_legacy_scope (
898
- ident, invoc_id , invocation . parent_legacy_scope . get ( ) , true , kind == MacroKind :: Attr
900
+ ident, parent_expansion , parent_legacy_scope, true , kind == MacroKind :: Attr
899
901
) ;
900
902
let resolution = self . resolve_lexical_macro_path_segment (
901
- ident, MacroNS , invoc_id , true , true , kind == MacroKind :: Attr , span
903
+ ident, MacroNS , parent_expansion , true , true , kind == MacroKind :: Attr , span
902
904
) ;
903
905
904
906
let check_consistency = |this : & Self , new_def : Def | {
@@ -932,12 +934,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
932
934
err. emit ( ) ;
933
935
} ,
934
936
( Some ( legacy_binding) , Ok ( ( binding, FromPrelude ( from_prelude) ) ) )
935
- if !from_prelude || legacy_binding. may_appear_after ( invoc_id , binding ) => {
936
- if legacy_binding . def_ignoring_ambiguity ( ) != binding . def_ignoring_ambiguity ( ) {
937
- self . report_ambiguity_error ( ident , legacy_binding , binding) ;
938
- }
937
+ if legacy_binding. def ( ) != binding . def_ignoring_ambiguity ( ) &&
938
+ ( !from_prelude ||
939
+ legacy_binding . may_appear_after ( parent_expansion , binding) ) => {
940
+ self . report_ambiguity_error ( ident , legacy_binding , binding ) ;
939
941
} ,
940
942
// OK, non-macro-expanded legacy wins over prelude even if defs are different
943
+ // Also, legacy and modern can co-exist if their defs are same
941
944
( Some ( legacy_binding) , Ok ( _) ) |
942
945
// OK, unambiguous resolution
943
946
( Some ( legacy_binding) , Err ( _) ) => {
0 commit comments