@@ -30,7 +30,8 @@ struct CfgPropagator<'a, 'tcx> {
3030 cfg_info : CfgInfo ,
3131}
3232
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 {
3435 // We only keep `doc(cfg)` items.
3536 matches ! (
3637 token,
@@ -47,7 +48,9 @@ fn should_retain(token: &TokenTree) -> bool {
4748 )
4849}
4950
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 > {
5154 let mut tokens = Vec :: with_capacity ( args_tokens. len ( ) ) ;
5255 let mut skip_next_delimited = false ;
5356 for token in args_tokens. iter ( ) {
@@ -58,7 +61,7 @@ fn filter_tokens_from_list(args_tokens: &TokenStream) -> Vec<TokenTree> {
5861 }
5962 skip_next_delimited = false ;
6063 }
61- token if should_retain ( token) => {
64+ token if is_cfg_token ( token) => {
6265 skip_next_delimited = false ;
6366 tokens. push ( token. clone ( ) ) ;
6467 }
@@ -70,7 +73,8 @@ fn filter_tokens_from_list(args_tokens: &TokenStream) -> Vec<TokenTree> {
7073 tokens
7174}
7275
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`.
7478fn add_only_cfg_attributes ( attrs : & mut Vec < Attribute > , new_attrs : & [ Attribute ] ) {
7579 for attr in new_attrs {
7680 if attr. is_doc_comment ( ) {
@@ -84,7 +88,7 @@ fn add_only_cfg_attributes(attrs: &mut Vec<Attribute>, new_attrs: &[Attribute])
8488 if ident == sym:: doc
8589 && let AttrArgs :: Delimited ( args) = & mut normal. args
8690 {
87- let tokens = filter_tokens_from_list ( & args. tokens ) ;
91+ let tokens = filter_non_cfg_tokens_from_list ( & args. tokens ) ;
8892 args. tokens = TokenStream :: new ( tokens) ;
8993 attrs. push ( attr) ;
9094 } else if ident == sym:: cfg_trace {
0 commit comments