@@ -27,6 +27,8 @@ pub(crate) struct Module<'hir> {
27
27
pub ( crate ) where_inner : Span ,
28
28
pub ( crate ) mods : Vec < Module < ' hir > > ,
29
29
pub ( crate ) def_id : LocalDefId ,
30
+ pub ( crate ) renamed : Option < Symbol > ,
31
+ pub ( crate ) import_id : Option < LocalDefId > ,
30
32
/// The key is the item `ItemId` and the value is: (item, renamed, import_id).
31
33
/// We use `FxIndexMap` to keep the insert order.
32
34
pub ( crate ) items : FxIndexMap <
@@ -37,11 +39,19 @@ pub(crate) struct Module<'hir> {
37
39
}
38
40
39
41
impl 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 {
41
49
Module {
42
50
name,
43
51
def_id,
44
52
where_inner,
53
+ renamed,
54
+ import_id,
45
55
mods : Vec :: new ( ) ,
46
56
items : FxIndexMap :: default ( ) ,
47
57
foreigns : Vec :: new ( ) ,
@@ -60,9 +70,16 @@ fn def_id_to_path(tcx: TyCtxt<'_>, did: DefId) -> Vec<Symbol> {
60
70
std:: iter:: once ( crate_name) . chain ( relative) . collect ( )
61
71
}
62
72
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 {
64
78
let hir = tcx. hir ( ) ;
65
79
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
+ }
66
83
def_id = id;
67
84
if tcx. is_doc_hidden ( def_id. to_def_id ( ) ) {
68
85
return true ;
@@ -100,6 +117,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
100
117
cx. tcx . crate_name ( LOCAL_CRATE ) ,
101
118
CRATE_DEF_ID ,
102
119
cx. tcx . hir ( ) . root_module ( ) . spans . inner_span ,
120
+ None ,
121
+ None ,
103
122
) ;
104
123
105
124
RustdocVisitor {
@@ -260,7 +279,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
260
279
261
280
let is_private =
262
281
!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 ) ;
264
283
265
284
// Only inline if requested or if the item would otherwise be stripped.
266
285
if ( !please_inline && !is_private && !is_hidden) || is_no_inline {
@@ -277,7 +296,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
277
296
. cache
278
297
. effective_visibilities
279
298
. 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 )
281
300
{
282
301
// The imported item is public and not `doc(hidden)` so no need to inline it.
283
302
return false ;
@@ -426,7 +445,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
426
445
}
427
446
}
428
447
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 ) ;
430
449
}
431
450
hir:: ItemKind :: Fn ( ..)
432
451
| hir:: ItemKind :: ExternCrate ( ..)
@@ -479,8 +498,15 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
479
498
/// This method will create a new module and push it onto the "modules stack" then call
480
499
/// `visit_mod_contents`. Once done, it'll remove it from the "modules stack" and instead
481
500
/// 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) ) ;
484
510
485
511
self . visit_mod_contents ( id, m) ;
486
512
0 commit comments