1111use { AmbiguityError , CrateLint , Resolver , ResolutionError , resolve_error} ;
1212use { Module , ModuleKind , NameBinding , NameBindingKind , PathResult } ;
1313use Namespace :: { self , MacroNS } ;
14- use build_reduced_graph:: BuildReducedGraphVisitor ;
14+ use build_reduced_graph:: { BuildReducedGraphVisitor , IsMacroExport } ;
1515use resolve_imports:: ImportResolver ;
1616use rustc:: hir:: def_id:: { DefId , BUILTIN_MACROS_CRATE , CRATE_DEF_INDEX , DefIndex ,
1717 DefIndexAddressSpace } ;
@@ -193,7 +193,9 @@ impl<'a> base::Resolver for Resolver<'a> {
193193
194194 self . current_module = invocation. module . get ( ) ;
195195 self . current_module . unresolved_invocations . borrow_mut ( ) . remove ( & mark) ;
196+ self . unresolved_invocations_macro_export . remove ( & mark) ;
196197 self . current_module . unresolved_invocations . borrow_mut ( ) . extend ( derives) ;
198+ self . unresolved_invocations_macro_export . extend ( derives) ;
197199 for & derive in derives {
198200 self . invocations . insert ( derive, invocation) ;
199201 }
@@ -215,7 +217,7 @@ impl<'a> base::Resolver for Resolver<'a> {
215217 let kind = ext. kind ( ) ;
216218 self . macro_map . insert ( def_id, ext) ;
217219 let binding = self . arenas . alloc_name_binding ( NameBinding {
218- kind : NameBindingKind :: Def ( Def :: Macro ( def_id, kind) ) ,
220+ kind : NameBindingKind :: Def ( Def :: Macro ( def_id, kind) , false ) ,
219221 span : DUMMY_SP ,
220222 vis : ty:: Visibility :: Invisible ,
221223 expansion : Mark :: root ( ) ,
@@ -711,12 +713,15 @@ impl<'a> Resolver<'a> {
711713
712714 match ( legacy_resolution, resolution) {
713715 ( Some ( MacroBinding :: Legacy ( legacy_binding) ) , Ok ( MacroBinding :: Modern ( binding) ) ) => {
714- let msg1 = format ! ( "`{}` could refer to the macro defined here" , ident) ;
715- let msg2 = format ! ( "`{}` could also refer to the macro imported here" , ident) ;
716- self . session . struct_span_err ( span, & format ! ( "`{}` is ambiguous" , ident) )
717- . span_note ( legacy_binding. span , & msg1)
718- . span_note ( binding. span , & msg2)
719- . emit ( ) ;
716+ if legacy_binding. def_id != binding. def_ignoring_ambiguity ( ) . def_id ( ) {
717+ let msg1 = format ! ( "`{}` could refer to the macro defined here" , ident) ;
718+ let msg2 =
719+ format ! ( "`{}` could also refer to the macro imported here" , ident) ;
720+ self . session . struct_span_err ( span, & format ! ( "`{}` is ambiguous" , ident) )
721+ . span_note ( legacy_binding. span , & msg1)
722+ . span_note ( binding. span , & msg2)
723+ . emit ( ) ;
724+ }
720725 } ,
721726 ( None , Err ( _) ) => {
722727 assert ! ( def. is_none( ) ) ;
@@ -850,12 +855,19 @@ impl<'a> Resolver<'a> {
850855 let def = Def :: Macro ( def_id, MacroKind :: Bang ) ;
851856 self . all_macros . insert ( ident. name , def) ;
852857 if attr:: contains_name ( & item. attrs , "macro_export" ) {
853- self . macro_exports . push ( Export {
854- ident : ident. modern ( ) ,
855- def : def,
856- vis : ty:: Visibility :: Public ,
857- span : item. span ,
858- } ) ;
858+ if self . use_extern_macros {
859+ let module = self . graph_root ;
860+ let vis = ty:: Visibility :: Public ;
861+ self . define ( module, ident, MacroNS ,
862+ ( def, vis, item. span , expansion, IsMacroExport ) ) ;
863+ } else {
864+ self . macro_exports . push ( Export {
865+ ident : ident. modern ( ) ,
866+ def : def,
867+ vis : ty:: Visibility :: Public ,
868+ span : item. span ,
869+ } ) ;
870+ }
859871 } else {
860872 self . unused_macros . insert ( def_id) ;
861873 }
0 commit comments