1
1
//! A collection of utility functions for the `strip_*` passes.
2
2
use rustc_hir:: def_id:: DefId ;
3
- use rustc_middle:: middle :: privacy :: EffectiveVisibilities ;
3
+ use rustc_middle:: ty :: TyCtxt ;
4
4
use rustc_span:: symbol:: sym;
5
5
6
6
use std:: mem;
7
7
8
8
use crate :: clean:: { self , Item , ItemId , ItemIdSet , NestedAttributesExt } ;
9
9
use crate :: fold:: { strip_item, DocFolder } ;
10
10
use crate :: formats:: cache:: Cache ;
11
+ use crate :: visit_lib:: RustdocEffectiveVisibilities ;
11
12
12
- pub ( crate ) struct Stripper < ' a > {
13
+ pub ( crate ) struct Stripper < ' a , ' tcx > {
14
+ pub ( crate ) tcx : TyCtxt < ' tcx > ,
13
15
pub ( crate ) retained : & ' a mut ItemIdSet ,
14
- pub ( crate ) effective_visibilities : & ' a EffectiveVisibilities < DefId > ,
16
+ pub ( crate ) effective_visibilities : & ' a RustdocEffectiveVisibilities ,
15
17
pub ( crate ) update_retained : bool ,
16
18
pub ( crate ) is_json_output : bool ,
17
19
}
@@ -21,18 +23,19 @@ pub(crate) struct Stripper<'a> {
21
23
// are in the public API, which is not enough.
22
24
#[ inline]
23
25
fn is_item_reachable (
26
+ tcx : TyCtxt < ' _ > ,
24
27
is_json_output : bool ,
25
- effective_visibilities : & EffectiveVisibilities < DefId > ,
28
+ effective_visibilities : & RustdocEffectiveVisibilities ,
26
29
item_id : ItemId ,
27
30
) -> bool {
28
31
if is_json_output {
29
- effective_visibilities. is_reachable ( item_id. expect_def_id ( ) )
32
+ effective_visibilities. is_reachable ( tcx , item_id. expect_def_id ( ) )
30
33
} else {
31
- effective_visibilities. is_exported ( item_id. expect_def_id ( ) )
34
+ effective_visibilities. is_exported ( tcx , item_id. expect_def_id ( ) )
32
35
}
33
36
}
34
37
35
- impl < ' a > DocFolder for Stripper < ' a > {
38
+ impl < ' a > DocFolder for Stripper < ' a , ' _ > {
36
39
fn fold_item ( & mut self , i : Item ) -> Option < Item > {
37
40
match * i. kind {
38
41
clean:: StrippedItem ( ..) => {
@@ -66,7 +69,12 @@ impl<'a> DocFolder for Stripper<'a> {
66
69
| clean:: ForeignTypeItem => {
67
70
let item_id = i. item_id ;
68
71
if item_id. is_local ( )
69
- && !is_item_reachable ( self . is_json_output , self . effective_visibilities , item_id)
72
+ && !is_item_reachable (
73
+ self . tcx ,
74
+ self . is_json_output ,
75
+ self . effective_visibilities ,
76
+ item_id,
77
+ )
70
78
{
71
79
debug ! ( "Stripper: stripping {:?} {:?}" , i. type_( ) , i. name) ;
72
80
return None ;
@@ -146,30 +154,31 @@ impl<'a> DocFolder for Stripper<'a> {
146
154
}
147
155
148
156
/// This stripper discards all impls which reference stripped items
149
- pub ( crate ) struct ImplStripper < ' a > {
157
+ pub ( crate ) struct ImplStripper < ' a , ' tcx > {
158
+ pub ( crate ) tcx : TyCtxt < ' tcx > ,
150
159
pub ( crate ) retained : & ' a ItemIdSet ,
151
160
pub ( crate ) cache : & ' a Cache ,
152
161
pub ( crate ) is_json_output : bool ,
153
162
pub ( crate ) document_private : bool ,
154
163
}
155
164
156
- impl < ' a > ImplStripper < ' a > {
165
+ impl < ' a > ImplStripper < ' a , ' _ > {
157
166
#[ inline]
158
167
fn should_keep_impl ( & self , item : & Item , for_def_id : DefId ) -> bool {
159
168
if !for_def_id. is_local ( ) || self . retained . contains ( & for_def_id. into ( ) ) {
160
169
true
161
170
} else if self . is_json_output {
162
171
// If the "for" item is exported and the impl block isn't `#[doc(hidden)]`, then we
163
172
// need to keep it.
164
- self . cache . effective_visibilities . is_exported ( for_def_id)
173
+ self . cache . effective_visibilities . is_exported ( self . tcx , for_def_id)
165
174
&& !item. attrs . lists ( sym:: doc) . has_word ( sym:: hidden)
166
175
} else {
167
176
false
168
177
}
169
178
}
170
179
}
171
180
172
- impl < ' a > DocFolder for ImplStripper < ' a > {
181
+ impl < ' a > DocFolder for ImplStripper < ' a , ' _ > {
173
182
fn fold_item ( & mut self , i : Item ) -> Option < Item > {
174
183
if let clean:: ImplItem ( ref imp) = * i. kind {
175
184
// Impl blocks can be skipped if they are: empty; not a trait impl; and have no
@@ -185,6 +194,7 @@ impl<'a> DocFolder for ImplStripper<'a> {
185
194
let item_id = i. item_id ;
186
195
item_id. is_local ( )
187
196
&& !is_item_reachable (
197
+ self . tcx ,
188
198
self . is_json_output ,
189
199
& self . cache . effective_visibilities ,
190
200
item_id,
0 commit comments