@@ -30,7 +30,8 @@ struct CfgPropagator<'a, 'tcx> {
30
30
cfg_info : CfgInfo ,
31
31
}
32
32
33
- fn should_retain ( token : & TokenTree ) -> bool {
33
+ /// Returns true if the provided `token` is a `cfg` ident.
34
+ fn is_cfg_token ( token : & TokenTree ) -> bool {
34
35
// We only keep `doc(cfg)` items.
35
36
matches ! (
36
37
token,
@@ -47,7 +48,9 @@ fn should_retain(token: &TokenTree) -> bool {
47
48
)
48
49
}
49
50
50
- fn filter_tokens_from_list ( args_tokens : & TokenStream ) -> Vec < TokenTree > {
51
+ /// We only want to keep `#[cfg()]` and `#[doc(cfg())]` attributes so we rebuild a vec of
52
+ /// `TokenTree` with only the tokens we're interested into.
53
+ fn filter_non_cfg_tokens_from_list ( args_tokens : & TokenStream ) -> Vec < TokenTree > {
51
54
let mut tokens = Vec :: with_capacity ( args_tokens. len ( ) ) ;
52
55
let mut skip_next_delimited = false ;
53
56
for token in args_tokens. iter ( ) {
@@ -58,7 +61,7 @@ fn filter_tokens_from_list(args_tokens: &TokenStream) -> Vec<TokenTree> {
58
61
}
59
62
skip_next_delimited = false ;
60
63
}
61
- token if should_retain ( token) => {
64
+ token if is_cfg_token ( token) => {
62
65
skip_next_delimited = false ;
63
66
tokens. push ( token. clone ( ) ) ;
64
67
}
@@ -70,7 +73,8 @@ fn filter_tokens_from_list(args_tokens: &TokenStream) -> Vec<TokenTree> {
70
73
tokens
71
74
}
72
75
73
- // We only care about `#[cfg()]` and `#[doc(cfg())]`, we discard everything else.
76
+ /// This function goes through the attributes list (`new_attrs`) and extract the `cfg` tokens from
77
+ /// it and put them into `attrs`.
74
78
fn add_only_cfg_attributes ( attrs : & mut Vec < Attribute > , new_attrs : & [ Attribute ] ) {
75
79
for attr in new_attrs {
76
80
if attr. is_doc_comment ( ) {
@@ -84,7 +88,7 @@ fn add_only_cfg_attributes(attrs: &mut Vec<Attribute>, new_attrs: &[Attribute])
84
88
if ident == sym:: doc
85
89
&& let AttrArgs :: Delimited ( args) = & mut normal. args
86
90
{
87
- let tokens = filter_tokens_from_list ( & args. tokens ) ;
91
+ let tokens = filter_non_cfg_tokens_from_list ( & args. tokens ) ;
88
92
args. tokens = TokenStream :: new ( tokens) ;
89
93
attrs. push ( attr) ;
90
94
} else if ident == sym:: cfg_trace {
0 commit comments