@@ -17,6 +17,7 @@ use rustc_data_structures::intern::Interned;
1717use rustc_errors:: { pluralize, struct_span_err, Applicability , MultiSpan } ;
1818use rustc_hir:: def:: { self , DefKind , PartialRes } ;
1919use rustc_middle:: metadata:: ModChild ;
20+ use rustc_middle:: metadata:: Reexport ;
2021use rustc_middle:: span_bug;
2122use rustc_middle:: ty;
2223use rustc_session:: lint:: builtin:: {
@@ -27,6 +28,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
2728use rustc_span:: hygiene:: LocalExpnId ;
2829use rustc_span:: symbol:: { kw, Ident , Symbol } ;
2930use rustc_span:: Span ;
31+ use smallvec:: SmallVec ;
3032
3133use std:: cell:: Cell ;
3234use std:: { mem, ptr} ;
@@ -190,6 +192,17 @@ impl<'a> Import<'a> {
190192 ImportKind :: MacroUse | ImportKind :: MacroExport => None ,
191193 }
192194 }
195+
196+ fn simplify ( & self , r : & Resolver < ' _ , ' _ > ) -> Reexport {
197+ let to_def_id = |id| r. local_def_id ( id) . to_def_id ( ) ;
198+ match self . kind {
199+ ImportKind :: Single { id, .. } => Reexport :: Single ( to_def_id ( id) ) ,
200+ ImportKind :: Glob { id, .. } => Reexport :: Glob ( to_def_id ( id) ) ,
201+ ImportKind :: ExternCrate { id, .. } => Reexport :: ExternCrate ( to_def_id ( id) ) ,
202+ ImportKind :: MacroUse => Reexport :: MacroUse ,
203+ ImportKind :: MacroExport => Reexport :: MacroExport ,
204+ }
205+ }
193206}
194207
195208/// Records information about the resolution of a name in a namespace of a module.
@@ -1252,12 +1265,20 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12521265
12531266 module. for_each_child ( self , |this, ident, _, binding| {
12541267 if let Some ( res) = this. is_reexport ( binding) {
1268+ let mut reexport_chain = SmallVec :: new ( ) ;
1269+ let mut next_binding = binding;
1270+ while let NameBindingKind :: Import { binding, import, .. } = next_binding. kind {
1271+ reexport_chain. push ( import. simplify ( this) ) ;
1272+ next_binding = binding;
1273+ }
1274+
12551275 reexports. push ( ModChild {
12561276 ident,
12571277 res,
12581278 vis : binding. vis ,
12591279 span : binding. span ,
12601280 macro_rules : false ,
1281+ reexport_chain,
12611282 } ) ;
12621283 }
12631284 } ) ;
0 commit comments