@@ -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 {
@@ -260,7 +279,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
260279
261280 let is_private =
262281 !self . cx . cache . effective_visibilities . is_directly_public ( self . cx . tcx , ori_res_did) ;
263- let is_hidden = inherits_doc_hidden ( self . cx . tcx , res_did) ;
282+ let is_hidden = inherits_doc_hidden ( self . cx . tcx , res_did, None ) ;
264283
265284 // Only inline if requested or if the item would otherwise be stripped.
266285 if ( !please_inline && !is_private && !is_hidden) || is_no_inline {
@@ -277,7 +296,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
277296 . cache
278297 . effective_visibilities
279298 . is_directly_public ( self . cx . tcx , item_def_id. to_def_id ( ) ) &&
280- !inherits_doc_hidden ( self . cx . tcx , item_def_id)
299+ !inherits_doc_hidden ( self . cx . tcx , item_def_id, None )
281300 {
282301 // The imported item is public and not `doc(hidden)` so no need to inline it.
283302 return false ;
@@ -426,7 +445,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
426445 }
427446 }
428447 hir:: ItemKind :: Mod ( ref m) => {
429- self . enter_mod ( item. owner_id . def_id , m, name) ;
448+ self . enter_mod ( item. owner_id . def_id , m, name, renamed , import_id ) ;
430449 }
431450 hir:: ItemKind :: Fn ( ..)
432451 | hir:: ItemKind :: ExternCrate ( ..)
@@ -479,8 +498,15 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
479498 /// This method will create a new module and push it onto the "modules stack" then call
480499 /// `visit_mod_contents`. Once done, it'll remove it from the "modules stack" and instead
481500 /// add into the list of modules of the current module.
482- fn enter_mod ( & mut self , id : LocalDefId , m : & ' tcx hir:: Mod < ' tcx > , name : Symbol ) {
483- self . modules . push ( Module :: new ( name, id, m. spans . inner_span ) ) ;
501+ fn enter_mod (
502+ & mut self ,
503+ id : LocalDefId ,
504+ m : & ' tcx hir:: Mod < ' tcx > ,
505+ name : Symbol ,
506+ renamed : Option < Symbol > ,
507+ import_id : Option < LocalDefId > ,
508+ ) {
509+ self . modules . push ( Module :: new ( name, id, m. spans . inner_span , renamed, import_id) ) ;
484510
485511 self . visit_mod_contents ( id, m) ;
486512
0 commit comments