@@ -14,7 +14,7 @@ use rustc_span::hygiene::MacroKind;
1414use rustc_span:: symbol:: { kw, sym, Symbol } ;
1515use rustc_span:: Span ;
1616
17- use std:: { iter , mem} ;
17+ use std:: mem;
1818
1919use crate :: clean:: { cfg:: Cfg , reexport_chain, AttributesExt , NestedAttributesExt } ;
2020use crate :: core;
@@ -291,27 +291,15 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
291291 if !please_inline {
292292 let inherits_hidden = inherits_doc_hidden ( tcx, res_did, None ) ;
293293 // Only inline if requested or if the item would otherwise be stripped.
294- //
295- // If it's a doc hidden module, we need to keep it in case some of its inner items
296- // are re-exported.
297294 if ( !is_private && !inherits_hidden) || (
298295 is_hidden &&
296+ // If it's a doc hidden module, we need to keep it in case some of its inner items
297+ // are re-exported.
299298 !matches ! ( item, Node :: Item ( & hir:: Item { kind: hir:: ItemKind :: Mod ( _) , .. } ) )
300- ) {
301- return false ;
302- } else if let Some ( item_def_id) = reexport_chain ( tcx, def_id, res_did) . iter ( )
303- . flat_map ( |reexport| reexport. id ( ) ) . map ( |id| id. expect_local ( ) )
304- . chain ( iter:: once ( res_did) ) . nth ( 1 ) &&
305- item_def_id != def_id &&
306- self
307- . cx
308- . cache
309- . effective_visibilities
310- . is_directly_public ( tcx, item_def_id. to_def_id ( ) ) &&
311- !tcx. is_doc_hidden ( item_def_id) &&
312- !inherits_doc_hidden ( tcx, item_def_id, None )
313- {
299+ ) ||
314300 // The imported item is public and not `doc(hidden)` so no need to inline it.
301+ self . reexport_public_and_not_hidden ( def_id, res_did)
302+ {
315303 return false ;
316304 }
317305 }
@@ -359,6 +347,28 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
359347 ret
360348 }
361349
350+ /// Returns `true` if the item is visible, meaning it's not `#[doc(hidden)]` or private.
351+ ///
352+ /// This function takes into account the entire re-export `use` chain, so it needs the
353+ /// ID of the "leaf" `use` and the ID of the "root" item.
354+ fn reexport_public_and_not_hidden (
355+ & self ,
356+ import_def_id : LocalDefId ,
357+ target_def_id : LocalDefId ,
358+ ) -> bool {
359+ let tcx = self . cx . tcx ;
360+ let item_def_id = reexport_chain ( tcx, import_def_id, target_def_id)
361+ . iter ( )
362+ . flat_map ( |reexport| reexport. id ( ) )
363+ . map ( |id| id. expect_local ( ) )
364+ . nth ( 1 )
365+ . unwrap_or ( target_def_id) ;
366+ item_def_id != import_def_id
367+ && self . cx . cache . effective_visibilities . is_directly_public ( tcx, item_def_id. to_def_id ( ) )
368+ && !tcx. is_doc_hidden ( item_def_id)
369+ && !inherits_doc_hidden ( tcx, item_def_id, None )
370+ }
371+
362372 #[ inline]
363373 fn add_to_current_mod (
364374 & mut self ,
0 commit comments