11//! Propagates [`#[doc(cfg(...))]`](https://github.com/rust-lang/rust/issues/43781) to child items.
22
3- use std:: sync:: Arc ;
4-
53use rustc_ast:: token:: { Token , TokenKind } ;
64use rustc_ast:: tokenstream:: { TokenStream , TokenTree } ;
7- use rustc_hir:: def_id:: LocalDefId ;
85use rustc_hir:: { AttrArgs , Attribute } ;
96use rustc_span:: symbol:: sym;
107
11- use crate :: clean:: cfg:: Cfg ;
128use crate :: clean:: inline:: { load_attrs, merge_attrs} ;
139use crate :: clean:: { CfgInfo , Crate , Item , ItemKind } ;
1410use crate :: core:: DocContext ;
@@ -22,13 +18,10 @@ pub(crate) const PROPAGATE_DOC_CFG: Pass = Pass {
2218} ;
2319
2420pub ( crate ) fn propagate_doc_cfg ( cr : Crate , cx : & mut DocContext < ' _ > ) -> Crate {
25- CfgPropagator { parent_cfg : None , parent : None , cx, cfg_info : CfgInfo :: default ( ) }
26- . fold_crate ( cr)
21+ CfgPropagator { cx, cfg_info : CfgInfo :: default ( ) } . fold_crate ( cr)
2722}
2823
2924struct CfgPropagator < ' a , ' tcx > {
30- parent_cfg : Option < Arc < Cfg > > ,
31- parent : Option < LocalDefId > ,
3225 cx : & ' a mut DocContext < ' tcx > ,
3326 cfg_info : CfgInfo ,
3427}
@@ -131,21 +124,11 @@ impl CfgPropagator<'_, '_> {
131124impl DocFolder for CfgPropagator < ' _ , ' _ > {
132125 fn fold_item ( & mut self , mut item : Item ) -> Option < Item > {
133126 let old_cfg_info = self . cfg_info . clone ( ) ;
134- let old_parent_cfg = self . parent_cfg . clone ( ) ;
135127
136128 self . merge_with_parent_attributes ( & mut item) ;
137- self . parent_cfg = item. inner . cfg . clone ( ) ;
138129
139- let old_parent =
140- if let Some ( def_id) = item. item_id . as_def_id ( ) . and_then ( |def_id| def_id. as_local ( ) ) {
141- self . parent . replace ( def_id)
142- } else {
143- self . parent . take ( )
144- } ;
145130 let result = self . fold_item_recur ( item) ;
146131 self . cfg_info = old_cfg_info;
147- self . parent_cfg = old_parent_cfg;
148- self . parent = old_parent;
149132
150133 Some ( result)
151134 }
0 commit comments