@@ -313,7 +313,7 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
313313 None
314314 }
315315
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 )
317317 -> Result < Option < Lrc < SyntaxExtension > > , Determinacy > {
318318 let ( path, kind, derives_in_scope) = match invoc. kind {
319319 InvocationKind :: Attr { attr : None , .. } =>
@@ -326,7 +326,7 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
326326 ( path, MacroKind :: Derive , & [ ] [ ..] ) ,
327327 } ;
328328
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) ?;
330330
331331 if let Def :: Macro ( def_id, _) = def {
332332 self . macro_defs . insert ( invoc. expansion_data . mark , def_id) ;
@@ -341,10 +341,10 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
341341 Ok ( Some ( ext) )
342342 }
343343
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 ,
345345 derives_in_scope : & [ ast:: Path ] , force : bool )
346346 -> 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 )
348348 }
349349
350350 fn check_unused_macros ( & self ) {
@@ -366,10 +366,10 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
366366}
367367
368368impl < ' 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 ,
370370 derives_in_scope : & [ ast:: Path ] , force : bool )
371371 -> 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) ;
373373
374374 // Report errors and enforce feature gates for the resolved macro.
375375 if def != Err ( Determinacy :: Undetermined ) {
@@ -439,8 +439,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
439439 let ast:: Path { ref segments, span } = * path;
440440 let mut path: Vec < _ > = segments. iter ( ) . map ( |seg| seg. ident ) . collect ( ) ;
441441 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 ( ) ;
444445
445446 // Possibly apply the macro helper hack
446447 if kind == MacroKind :: Bang && path. len ( ) == 1 &&
@@ -450,8 +451,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
450451 }
451452
452453 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 ) {
455457 PathResult :: NonModule ( path_res) => match path_res. base_def ( ) {
456458 Def :: Err => Err ( Determinacy :: Determined ) ,
457459 def @ _ => {
@@ -471,19 +473,19 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
471473 Err ( Determinacy :: Determined )
472474 } ,
473475 } ;
474- self . current_module . nearest_item_scope ( ) . macro_resolutions . borrow_mut ( )
476+ self . current_module . macro_resolutions . borrow_mut ( )
475477 . push ( ( path. into_boxed_slice ( ) , span) ) ;
476478 return def;
477479 }
478480
479481 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
481483 ) ;
482484 let result = if let Some ( legacy_binding) = legacy_resolution {
483485 Ok ( legacy_binding. def ( ) )
484486 } 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) {
487489 Ok ( ( binding, _) ) => Ok ( binding. def_ignoring_ambiguity ( ) ) ,
488490 Err ( Determinacy :: Undetermined ) => return Err ( Determinacy :: Undetermined ) ,
489491 Err ( Determinacy :: Determined ) => {
@@ -493,8 +495,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
493495 }
494496 } ;
495497
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 ( ) ) ) ;
498500
499501 if let Ok ( Def :: NonMacroAttr ( NonMacroAttrKind :: Custom ) ) = result { } else {
500502 return result;
@@ -541,7 +543,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
541543 & mut self ,
542544 mut ident : Ident ,
543545 ns : Namespace ,
544- invoc_id : Mark ,
546+ parent_expansion : Mark ,
545547 record_used : bool ,
546548 force : bool ,
547549 is_attr : bool ,
@@ -754,7 +756,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
754756 // Found another solution, if the first one was "weak", report an error.
755757 if result. 0 . def ( ) != innermost_result. 0 . def ( ) &&
756758 ( 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 ) ) {
758760 self . ambiguity_errors . push ( AmbiguityError {
759761 ident,
760762 b1 : innermost_result. 0 ,
@@ -798,8 +800,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
798800
799801 fn resolve_legacy_scope ( & mut self ,
800802 ident : Ident ,
801- invoc_id : Mark ,
802- invoc_parent_legacy_scope : LegacyScope < ' a > ,
803+ parent_expansion : Mark ,
804+ parent_legacy_scope : LegacyScope < ' a > ,
803805 record_used : bool ,
804806 is_attr : bool )
805807 -> Option < & ' a NameBinding < ' a > > {
@@ -826,7 +828,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
826828 let mut innermost_result: Option < & NameBinding > = None ;
827829
828830 // 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 ;
830832 loop {
831833 let result = match where_to_resolve {
832834 LegacyScope :: Binding ( legacy_binding) if ident == legacy_binding. ident =>
@@ -854,7 +856,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
854856 if let Some ( innermost_result) = innermost_result {
855857 // Found another solution, if the first one was "weak", report an error.
856858 if result. def ( ) != innermost_result. def ( ) &&
857- innermost_result. may_appear_after ( invoc_id , result) {
859+ innermost_result. may_appear_after ( parent_expansion , result) {
858860 self . ambiguity_errors . push ( AmbiguityError {
859861 ident,
860862 b1 : innermost_result,
@@ -891,14 +893,14 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
891893 }
892894 }
893895
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 ( ) {
895898 let span = ident. span ;
896- let invocation = self . invocations [ & invoc_id] ;
897899 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
899901 ) ;
900902 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
902904 ) ;
903905
904906 let check_consistency = |this : & Self , new_def : Def | {
@@ -932,12 +934,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
932934 err. emit ( ) ;
933935 } ,
934936 ( 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 ) ;
939941 } ,
940942 // 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
941944 ( Some ( legacy_binding) , Ok ( _) ) |
942945 // OK, unambiguous resolution
943946 ( Some ( legacy_binding) , Err ( _) ) => {
0 commit comments