11
11
use { AmbiguityError , CrateLint , Resolver , ResolutionError , resolve_error} ;
12
12
use { Module , ModuleKind , NameBinding , NameBindingKind , PathResult } ;
13
13
use Namespace :: { self , MacroNS } ;
14
- use build_reduced_graph:: BuildReducedGraphVisitor ;
14
+ use build_reduced_graph:: { BuildReducedGraphVisitor , IsMacroExport } ;
15
15
use resolve_imports:: ImportResolver ;
16
16
use rustc:: hir:: def_id:: { DefId , BUILTIN_MACROS_CRATE , CRATE_DEF_INDEX , DefIndex ,
17
17
DefIndexAddressSpace } ;
@@ -193,7 +193,9 @@ impl<'a> base::Resolver for Resolver<'a> {
193
193
194
194
self . current_module = invocation. module . get ( ) ;
195
195
self . current_module . unresolved_invocations . borrow_mut ( ) . remove ( & mark) ;
196
+ self . unresolved_invocations_macro_export . remove ( & mark) ;
196
197
self . current_module . unresolved_invocations . borrow_mut ( ) . extend ( derives) ;
198
+ self . unresolved_invocations_macro_export . extend ( derives) ;
197
199
for & derive in derives {
198
200
self . invocations . insert ( derive, invocation) ;
199
201
}
@@ -215,7 +217,7 @@ impl<'a> base::Resolver for Resolver<'a> {
215
217
let kind = ext. kind ( ) ;
216
218
self . macro_map . insert ( def_id, ext) ;
217
219
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 ) ,
219
221
span : DUMMY_SP ,
220
222
vis : ty:: Visibility :: Invisible ,
221
223
expansion : Mark :: root ( ) ,
@@ -711,12 +713,15 @@ impl<'a> Resolver<'a> {
711
713
712
714
match ( legacy_resolution, resolution) {
713
715
( 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
+ }
720
725
} ,
721
726
( None , Err ( _) ) => {
722
727
assert ! ( def. is_none( ) ) ;
@@ -850,12 +855,19 @@ impl<'a> Resolver<'a> {
850
855
let def = Def :: Macro ( def_id, MacroKind :: Bang ) ;
851
856
self . all_macros . insert ( ident. name , def) ;
852
857
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
+ }
859
871
} else {
860
872
self . unused_macros . insert ( def_id) ;
861
873
}
0 commit comments