@@ -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 {
@@ -261,7 +280,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
261
280
262
281
let is_private =
263
282
!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 ) ;
265
284
266
285
// Only inline if requested or if the item would otherwise be stripped.
267
286
if ( !please_inline && !is_private && !is_hidden) || is_no_inline {
@@ -278,7 +297,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
278
297
. cache
279
298
. effective_visibilities
280
299
. 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 )
282
301
{
283
302
// The imported item is public and not `doc(hidden)` so no need to inline it.
284
303
return false ;
@@ -427,7 +446,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
427
446
}
428
447
}
429
448
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 ) ;
431
450
}
432
451
hir:: ItemKind :: Fn ( ..)
433
452
| hir:: ItemKind :: ExternCrate ( ..)
@@ -480,8 +499,15 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
480
499
/// This method will create a new module and push it onto the "modules stack" then call
481
500
/// `visit_mod_contents`. Once done, it'll remove it from the "modules stack" and instead
482
501
/// 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) ) ;
485
511
486
512
self . visit_mod_contents ( id, m) ;
487
513
@@ -501,19 +527,14 @@ impl<'a, 'tcx> Visitor<'tcx> for RustdocVisitor<'a, 'tcx> {
501
527
502
528
fn visit_item ( & mut self , i : & ' tcx hir:: Item < ' tcx > ) {
503
529
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 ! (
506
532
i. kind,
507
533
hir:: ItemKind :: Mod ( ..)
508
534
| hir:: ItemKind :: ForeignMod { .. }
509
535
| hir:: ItemKind :: Impl ( ..)
510
536
| 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
+ ) ;
517
538
let prev = mem:: replace ( & mut self . is_importable_from_parent , new_value) ;
518
539
walk_item ( self , i) ;
519
540
self . is_importable_from_parent = prev;
0 commit comments