@@ -14,7 +14,7 @@ use rustc_span::hygiene::MacroKind;
14
14
use rustc_span:: symbol:: { kw, sym, Symbol } ;
15
15
use rustc_span:: Span ;
16
16
17
- use std:: { iter , mem} ;
17
+ use std:: mem;
18
18
19
19
use crate :: clean:: { cfg:: Cfg , reexport_chain, AttributesExt , NestedAttributesExt } ;
20
20
use crate :: core;
@@ -291,27 +291,15 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
291
291
if !please_inline {
292
292
let inherits_hidden = inherits_doc_hidden ( tcx, res_did, None ) ;
293
293
// 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.
297
294
if ( !is_private && !inherits_hidden) || (
298
295
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.
299
298
!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
+ ) ||
314
300
// 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
+ {
315
303
return false ;
316
304
}
317
305
}
@@ -359,6 +347,28 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
359
347
ret
360
348
}
361
349
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
+
362
372
#[ inline]
363
373
fn add_to_current_mod (
364
374
& mut self ,
0 commit comments