1
1
//! Strip all doc(hidden) items from the output.
2
2
3
+ use rustc_hir:: def_id:: LocalDefId ;
3
4
use rustc_middle:: ty:: TyCtxt ;
4
5
use rustc_span:: symbol:: sym;
5
6
use std:: mem;
@@ -29,6 +30,7 @@ pub(crate) fn strip_hidden(krate: clean::Crate, cx: &mut DocContext<'_>) -> clea
29
30
update_retained : true ,
30
31
tcx : cx. tcx ,
31
32
is_in_hidden_item : false ,
33
+ last_reexport : None ,
32
34
} ;
33
35
stripper. fold_crate ( krate)
34
36
} ;
@@ -49,13 +51,24 @@ struct Stripper<'a, 'tcx> {
49
51
update_retained : bool ,
50
52
tcx : TyCtxt < ' tcx > ,
51
53
is_in_hidden_item : bool ,
54
+ last_reexport : Option < LocalDefId > ,
52
55
}
53
56
54
57
impl < ' a , ' tcx > Stripper < ' a , ' tcx > {
58
+ fn set_last_reexport_then_fold_item ( & mut self , i : Item ) -> Item {
59
+ let prev_from_reexport = self . last_reexport ;
60
+ if i. inline_stmt_id . is_some ( ) {
61
+ self . last_reexport = i. item_id . as_def_id ( ) . and_then ( |def_id| def_id. as_local ( ) ) ;
62
+ }
63
+ let ret = self . fold_item_recur ( i) ;
64
+ self . last_reexport = prev_from_reexport;
65
+ ret
66
+ }
67
+
55
68
fn set_is_in_hidden_item_and_fold ( & mut self , is_in_hidden_item : bool , i : Item ) -> Item {
56
69
let prev = self . is_in_hidden_item ;
57
70
self . is_in_hidden_item |= is_in_hidden_item;
58
- let ret = self . fold_item_recur ( i) ;
71
+ let ret = self . set_last_reexport_then_fold_item ( i) ;
59
72
self . is_in_hidden_item = prev;
60
73
ret
61
74
}
@@ -64,7 +77,7 @@ impl<'a, 'tcx> Stripper<'a, 'tcx> {
64
77
/// of `is_in_hidden_item` to `true` because the impl children inherit its visibility.
65
78
fn recurse_in_impl_or_exported_macro ( & mut self , i : Item ) -> Item {
66
79
let prev = mem:: replace ( & mut self . is_in_hidden_item , false ) ;
67
- let ret = self . fold_item_recur ( i) ;
80
+ let ret = self . set_last_reexport_then_fold_item ( i) ;
68
81
self . is_in_hidden_item = prev;
69
82
ret
70
83
}
@@ -86,13 +99,20 @@ impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
86
99
if !is_impl_or_exported_macro {
87
100
is_hidden = self . is_in_hidden_item || has_doc_hidden;
88
101
if !is_hidden && i. inline_stmt_id . is_none ( ) {
89
- // We don't need to check if it's coming from a reexport since the reexport itself was
90
- // already checked.
102
+ // `i.inline_stmt_id` is `Some` if the item is directly reexported. If it is, we
103
+ // don't need to check it, because the reexport itself was already checked.
104
+ //
105
+ // If this item is the child of a reexported module, `self.last_reexport` will be
106
+ // `Some` even though `i.inline_stmt_id` is `None`. Hiddenness inheritance needs to
107
+ // account for the possibility that an item's true parent module is hidden, but it's
108
+ // inlined into a visible module true. This code shouldn't be reachable if the
109
+ // module's reexport is itself hidden, for the same reason it doesn't need to be
110
+ // checked if `i.inline_stmt_id` is Some: hidden reexports are never inlined.
91
111
is_hidden = i
92
112
. item_id
93
113
. as_def_id ( )
94
114
. and_then ( |def_id| def_id. as_local ( ) )
95
- . map ( |def_id| inherits_doc_hidden ( self . tcx , def_id) )
115
+ . map ( |def_id| inherits_doc_hidden ( self . tcx , def_id, self . last_reexport ) )
96
116
. unwrap_or ( false ) ;
97
117
}
98
118
}
0 commit comments