11//! A collection of utility functions for the `strip_*` passes.
22use rustc_hir:: def_id:: DefId ;
3- use rustc_middle:: middle :: privacy :: EffectiveVisibilities ;
3+ use rustc_middle:: ty :: TyCtxt ;
44use rustc_span:: symbol:: sym;
55
66use std:: mem;
77
88use crate :: clean:: { self , Item , ItemId , ItemIdSet , NestedAttributesExt } ;
99use crate :: fold:: { strip_item, DocFolder } ;
1010use crate :: formats:: cache:: Cache ;
11+ use crate :: visit_lib:: RustdocEffectiveVisibilities ;
1112
12- pub ( crate ) struct Stripper < ' a > {
13+ pub ( crate ) struct Stripper < ' a , ' tcx > {
14+ pub ( crate ) tcx : TyCtxt < ' tcx > ,
1315 pub ( crate ) retained : & ' a mut ItemIdSet ,
14- pub ( crate ) effective_visibilities : & ' a EffectiveVisibilities < DefId > ,
16+ pub ( crate ) effective_visibilities : & ' a RustdocEffectiveVisibilities ,
1517 pub ( crate ) update_retained : bool ,
1618 pub ( crate ) is_json_output : bool ,
1719}
@@ -21,18 +23,19 @@ pub(crate) struct Stripper<'a> {
2123// are in the public API, which is not enough.
2224#[ inline]
2325fn is_item_reachable (
26+ tcx : TyCtxt < ' _ > ,
2427 is_json_output : bool ,
25- effective_visibilities : & EffectiveVisibilities < DefId > ,
28+ effective_visibilities : & RustdocEffectiveVisibilities ,
2629 item_id : ItemId ,
2730) -> bool {
2831 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 ( ) )
3033 } else {
31- effective_visibilities. is_exported ( item_id. expect_def_id ( ) )
34+ effective_visibilities. is_exported ( tcx , item_id. expect_def_id ( ) )
3235 }
3336}
3437
35- impl < ' a > DocFolder for Stripper < ' a > {
38+ impl < ' a > DocFolder for Stripper < ' a , ' _ > {
3639 fn fold_item ( & mut self , i : Item ) -> Option < Item > {
3740 match * i. kind {
3841 clean:: StrippedItem ( ..) => {
@@ -66,7 +69,12 @@ impl<'a> DocFolder for Stripper<'a> {
6669 | clean:: ForeignTypeItem => {
6770 let item_id = i. item_id ;
6871 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+ )
7078 {
7179 debug ! ( "Stripper: stripping {:?} {:?}" , i. type_( ) , i. name) ;
7280 return None ;
@@ -146,30 +154,31 @@ impl<'a> DocFolder for Stripper<'a> {
146154}
147155
148156/// 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 > ,
150159 pub ( crate ) retained : & ' a ItemIdSet ,
151160 pub ( crate ) cache : & ' a Cache ,
152161 pub ( crate ) is_json_output : bool ,
153162 pub ( crate ) document_private : bool ,
154163}
155164
156- impl < ' a > ImplStripper < ' a > {
165+ impl < ' a > ImplStripper < ' a , ' _ > {
157166 #[ inline]
158167 fn should_keep_impl ( & self , item : & Item , for_def_id : DefId ) -> bool {
159168 if !for_def_id. is_local ( ) || self . retained . contains ( & for_def_id. into ( ) ) {
160169 true
161170 } else if self . is_json_output {
162171 // If the "for" item is exported and the impl block isn't `#[doc(hidden)]`, then we
163172 // 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)
165174 && !item. attrs . lists ( sym:: doc) . has_word ( sym:: hidden)
166175 } else {
167176 false
168177 }
169178 }
170179}
171180
172- impl < ' a > DocFolder for ImplStripper < ' a > {
181+ impl < ' a > DocFolder for ImplStripper < ' a , ' _ > {
173182 fn fold_item ( & mut self , i : Item ) -> Option < Item > {
174183 if let clean:: ImplItem ( ref imp) = * i. kind {
175184 // 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> {
185194 let item_id = i. item_id ;
186195 item_id. is_local ( )
187196 && !is_item_reachable (
197+ self . tcx ,
188198 self . is_json_output ,
189199 & self . cache . effective_visibilities ,
190200 item_id,
0 commit comments