@@ -16,7 +16,7 @@ use rustc_data_structures::fx::FxHashSet;
1616use rustc_data_structures:: ptr_key:: PtrKey ;
1717use rustc_errors:: { pluralize, struct_span_err, Applicability } ;
1818use rustc_hir:: def:: { self , PartialRes } ;
19- use rustc_hir:: def_id:: DefId ;
19+ use rustc_hir:: def_id:: { DefId , CRATE_DEF_INDEX } ;
2020use rustc_middle:: hir:: exports:: Export ;
2121use rustc_middle:: span_bug;
2222use rustc_middle:: ty;
@@ -1392,9 +1392,23 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
13921392 // FIXME: Implement actual cross-crate hygiene.
13931393 let is_good_import =
13941394 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) ;
13981412 reexports. push ( Export { ident, res, span : binding. span , vis : binding. vis } ) ;
13991413 }
14001414 }
0 commit comments