1
1
//! Propagates [`#[doc(cfg(...))]`](https://github.com/rust-lang/rust/issues/43781) to child items.
2
2
3
- use std:: sync:: Arc ;
4
-
5
3
use rustc_ast:: token:: { Token , TokenKind } ;
6
4
use rustc_ast:: tokenstream:: { TokenStream , TokenTree } ;
7
- use rustc_hir:: def_id:: LocalDefId ;
8
5
use rustc_hir:: { AttrArgs , Attribute } ;
9
6
use rustc_span:: symbol:: sym;
10
7
11
- use crate :: clean:: cfg:: Cfg ;
12
8
use crate :: clean:: inline:: { load_attrs, merge_attrs} ;
13
9
use crate :: clean:: { CfgInfo , Crate , Item , ItemKind } ;
14
10
use crate :: core:: DocContext ;
@@ -22,13 +18,10 @@ pub(crate) const PROPAGATE_DOC_CFG: Pass = Pass {
22
18
} ;
23
19
24
20
pub ( 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)
27
22
}
28
23
29
24
struct CfgPropagator < ' a , ' tcx > {
30
- parent_cfg : Option < Arc < Cfg > > ,
31
- parent : Option < LocalDefId > ,
32
25
cx : & ' a mut DocContext < ' tcx > ,
33
26
cfg_info : CfgInfo ,
34
27
}
@@ -131,21 +124,11 @@ impl CfgPropagator<'_, '_> {
131
124
impl DocFolder for CfgPropagator < ' _ , ' _ > {
132
125
fn fold_item ( & mut self , mut item : Item ) -> Option < Item > {
133
126
let old_cfg_info = self . cfg_info . clone ( ) ;
134
- let old_parent_cfg = self . parent_cfg . clone ( ) ;
135
127
136
128
self . merge_with_parent_attributes ( & mut item) ;
137
- self . parent_cfg = item. inner . cfg . clone ( ) ;
138
129
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
- } ;
145
130
let result = self . fold_item_recur ( item) ;
146
131
self . cfg_info = old_cfg_info;
147
- self . parent_cfg = old_parent_cfg;
148
- self . parent = old_parent;
149
132
150
133
Some ( result)
151
134
}
0 commit comments