@@ -16,7 +16,7 @@ use rustc_data_structures::fx::FxHashSet;
16
16
use rustc_data_structures:: ptr_key:: PtrKey ;
17
17
use rustc_errors:: { pluralize, struct_span_err, Applicability } ;
18
18
use rustc_hir:: def:: { self , PartialRes } ;
19
- use rustc_hir:: def_id:: DefId ;
19
+ use rustc_hir:: def_id:: { DefId , CRATE_DEF_INDEX } ;
20
20
use rustc_middle:: hir:: exports:: Export ;
21
21
use rustc_middle:: span_bug;
22
22
use rustc_middle:: ty;
@@ -1392,9 +1392,23 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
1392
1392
// FIXME: Implement actual cross-crate hygiene.
1393
1393
let is_good_import =
1394
1394
binding. is_import ( ) && !binding. is_ambiguity ( ) && !ident. span . from_expansion ( ) ;
1395
- if is_good_import || binding. is_macro_def ( ) {
1396
- let res = binding. res ( ) . map_id ( |id| this. local_def_id ( id) ) ;
1397
- if res != def:: Res :: Err {
1395
+ let res = binding. res ( ) ;
1396
+ if res == Res :: Err {
1397
+ // Do not insert failed resolutions.
1398
+ return ;
1399
+ } else if is_good_import {
1400
+ let res = res. map_id ( |id| this. local_def_id ( id) ) ;
1401
+ reexports. push ( Export { ident, res, span : binding. span , vis : binding. vis } ) ;
1402
+ } else if let NameBindingKind :: Res ( Res :: Def ( def_kind, macro_def_id) , true ) =
1403
+ binding. kind
1404
+ {
1405
+ let macro_is_at_root = macro_def_id
1406
+ . as_local ( )
1407
+ . and_then ( |macro_def_id| this. definitions . def_key ( macro_def_id) . parent )
1408
+ == Some ( CRATE_DEF_INDEX ) ;
1409
+ // Insert a re-export at crate root for exported macro_rules defined elsewhere.
1410
+ if module. parent . is_none ( ) && !macro_is_at_root {
1411
+ let res = def:: Res :: Def ( def_kind, macro_def_id) ;
1398
1412
reexports. push ( Export { ident, res, span : binding. span , vis : binding. vis } ) ;
1399
1413
}
1400
1414
}
0 commit comments