@@ -27,6 +27,8 @@ pub(crate) struct Module<'hir> {
2727 pub ( crate ) where_inner : Span ,
2828 pub ( crate ) mods : Vec < Module < ' hir > > ,
2929 pub ( crate ) def_id : LocalDefId ,
30+ pub ( crate ) renamed : Option < Symbol > ,
31+ pub ( crate ) import_id : Option < LocalDefId > ,
3032 /// The key is the item `ItemId` and the value is: (item, renamed, import_id).
3133 /// We use `FxIndexMap` to keep the insert order.
3234 pub ( crate ) items : FxIndexMap <
@@ -37,11 +39,19 @@ pub(crate) struct Module<'hir> {
3739}
3840
3941impl Module < ' _ > {
40- pub ( crate ) fn new ( name : Symbol , def_id : LocalDefId , where_inner : Span ) -> Self {
42+ pub ( crate ) fn new (
43+ name : Symbol ,
44+ def_id : LocalDefId ,
45+ where_inner : Span ,
46+ renamed : Option < Symbol > ,
47+ import_id : Option < LocalDefId > ,
48+ ) -> Self {
4149 Module {
4250 name,
4351 def_id,
4452 where_inner,
53+ renamed,
54+ import_id,
4555 mods : Vec :: new ( ) ,
4656 items : FxIndexMap :: default ( ) ,
4757 foreigns : Vec :: new ( ) ,
@@ -60,9 +70,16 @@ fn def_id_to_path(tcx: TyCtxt<'_>, did: DefId) -> Vec<Symbol> {
6070 std:: iter:: once ( crate_name) . chain ( relative) . collect ( )
6171}
6272
63- pub ( crate ) fn inherits_doc_hidden ( tcx : TyCtxt < ' _ > , mut def_id : LocalDefId ) -> bool {
73+ pub ( crate ) fn inherits_doc_hidden (
74+ tcx : TyCtxt < ' _ > ,
75+ mut def_id : LocalDefId ,
76+ stop_at : Option < LocalDefId > ,
77+ ) -> bool {
6478 let hir = tcx. hir ( ) ;
6579 while let Some ( id) = tcx. opt_local_parent ( def_id) {
80+ if let Some ( stop_at) = stop_at && id == stop_at {
81+ return false ;
82+ }
6683 def_id = id;
6784 if tcx. is_doc_hidden ( def_id. to_def_id ( ) ) {
6885 return true ;
@@ -100,6 +117,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
100117 cx. tcx . crate_name ( LOCAL_CRATE ) ,
101118 CRATE_DEF_ID ,
102119 cx. tcx . hir ( ) . root_module ( ) . spans . inner_span ,
120+ None ,
121+ None ,
103122 ) ;
104123
105124 RustdocVisitor {
@@ -261,7 +280,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
261280
262281 let is_private =
263282 !self . cx . cache . effective_visibilities . is_directly_public ( self . cx . tcx , ori_res_did) ;
264- let is_hidden = inherits_doc_hidden ( self . cx . tcx , res_did) ;
283+ let is_hidden = inherits_doc_hidden ( self . cx . tcx , res_did, None ) ;
265284
266285 // Only inline if requested or if the item would otherwise be stripped.
267286 if ( !please_inline && !is_private && !is_hidden) || is_no_inline {
@@ -278,7 +297,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
278297 . cache
279298 . effective_visibilities
280299 . is_directly_public ( self . cx . tcx , item_def_id. to_def_id ( ) ) &&
281- !inherits_doc_hidden ( self . cx . tcx , item_def_id)
300+ !inherits_doc_hidden ( self . cx . tcx , item_def_id, None )
282301 {
283302 // The imported item is public and not `doc(hidden)` so no need to inline it.
284303 return false ;
@@ -427,7 +446,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
427446 }
428447 }
429448 hir:: ItemKind :: Mod ( ref m) => {
430- self . enter_mod ( item. owner_id . def_id , m, name) ;
449+ self . enter_mod ( item. owner_id . def_id , m, name, renamed , import_id ) ;
431450 }
432451 hir:: ItemKind :: Fn ( ..)
433452 | hir:: ItemKind :: ExternCrate ( ..)
@@ -480,8 +499,15 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
480499 /// This method will create a new module and push it onto the "modules stack" then call
481500 /// `visit_mod_contents`. Once done, it'll remove it from the "modules stack" and instead
482501 /// add into the list of modules of the current module.
483- fn enter_mod ( & mut self , id : LocalDefId , m : & ' tcx hir:: Mod < ' tcx > , name : Symbol ) {
484- self . modules . push ( Module :: new ( name, id, m. spans . inner_span ) ) ;
502+ fn enter_mod (
503+ & mut self ,
504+ id : LocalDefId ,
505+ m : & ' tcx hir:: Mod < ' tcx > ,
506+ name : Symbol ,
507+ renamed : Option < Symbol > ,
508+ import_id : Option < LocalDefId > ,
509+ ) {
510+ self . modules . push ( Module :: new ( name, id, m. spans . inner_span , renamed, import_id) ) ;
485511
486512 self . visit_mod_contents ( id, m) ;
487513
@@ -501,19 +527,14 @@ impl<'a, 'tcx> Visitor<'tcx> for RustdocVisitor<'a, 'tcx> {
501527
502528 fn visit_item ( & mut self , i : & ' tcx hir:: Item < ' tcx > ) {
503529 self . visit_item_inner ( i, None , None ) ;
504- let new_value = if self . is_importable_from_parent {
505- matches ! (
530+ let new_value = self . is_importable_from_parent
531+ && matches ! (
506532 i. kind,
507533 hir:: ItemKind :: Mod ( ..)
508534 | hir:: ItemKind :: ForeignMod { .. }
509535 | hir:: ItemKind :: Impl ( ..)
510536 | hir:: ItemKind :: Trait ( ..)
511- )
512- } else {
513- // Whatever the context, if it's an impl block, the items inside it can be used so they
514- // should be visible.
515- matches ! ( i. kind, hir:: ItemKind :: Impl ( ..) )
516- } ;
537+ ) ;
517538 let prev = mem:: replace ( & mut self . is_importable_from_parent , new_value) ;
518539 walk_item ( self , i) ;
519540 self . is_importable_from_parent = prev;
0 commit comments