@@ -198,7 +198,7 @@ fn generate_item_with_correct_attrs(
198
198
|| ( is_glob_import ( cx. tcx , import_id)
199
199
&& ( cx. render_options . document_hidden || !cx. tcx . is_doc_hidden ( def_id) ) ) ;
200
200
let mut attrs = get_all_import_attributes ( cx, import_id, def_id, is_inline) ;
201
- add_without_unwanted_attributes ( & mut attrs , target_attrs, is_inline, None ) ;
201
+ attrs . extend ( add_without_unwanted_attributes ( target_attrs, is_inline, None ) ) ;
202
202
attrs
203
203
} else {
204
204
// We only keep the item's attributes.
@@ -2640,7 +2640,7 @@ fn get_all_import_attributes<'hir>(
2640
2640
first = false ;
2641
2641
// We don't add attributes of an intermediate re-export if it has `#[doc(hidden)]`.
2642
2642
} else if cx. render_options . document_hidden || !cx. tcx . is_doc_hidden ( def_id) {
2643
- add_without_unwanted_attributes ( & mut attrs , import_attrs, is_inline, Some ( def_id) ) ;
2643
+ attrs . extend ( add_without_unwanted_attributes ( import_attrs, is_inline, Some ( def_id) ) ) ;
2644
2644
}
2645
2645
}
2646
2646
attrs
@@ -2719,34 +2719,32 @@ fn filter_doc_attr(args: &mut hir::AttrArgs, is_inline: bool) {
2719
2719
/// * `doc(no_inline)`
2720
2720
/// * `doc(hidden)`
2721
2721
fn add_without_unwanted_attributes < ' hir > (
2722
- attrs : & mut Vec < ( Cow < ' hir , hir:: Attribute > , Option < DefId > ) > ,
2723
2722
new_attrs : & ' hir [ hir:: Attribute ] ,
2724
2723
is_inline : bool ,
2725
2724
import_parent : Option < DefId > ,
2726
- ) {
2727
- for attr in new_attrs {
2725
+ ) -> impl Iterator < Item = ( Cow < ' hir , hir :: Attribute > , Option < DefId > ) > {
2726
+ new_attrs . iter ( ) . filter_map ( move | attr| {
2728
2727
if attr. is_doc_comment ( ) {
2729
- attrs. push ( ( Cow :: Borrowed ( attr) , import_parent) ) ;
2730
- continue ;
2728
+ return Some ( ( Cow :: Borrowed ( attr) , import_parent) ) ;
2731
2729
}
2732
- let mut attr = attr. clone ( ) ;
2733
2730
match attr {
2734
- hir:: Attribute :: Unparsed ( ref mut normal) if let [ ident] = & * normal. path . segments => {
2731
+ hir:: Attribute :: Unparsed ( normal) if let [ ident] = & * normal. path . segments => {
2735
2732
let ident = ident. name ;
2736
2733
if ident == sym:: doc {
2734
+ let mut normal = normal. clone ( ) ;
2737
2735
filter_doc_attr ( & mut normal. args , is_inline) ;
2738
- attrs . push ( ( Cow :: Owned ( attr ) , import_parent) ) ;
2736
+ Some ( ( Cow :: Owned ( hir :: Attribute :: Unparsed ( normal ) ) , import_parent) )
2739
2737
} else if is_inline || ident != sym:: cfg_trace {
2740
2738
// If it's not a `cfg()` attribute, we keep it.
2741
- attrs. push ( ( Cow :: Owned ( attr) , import_parent) ) ;
2739
+ Some ( ( Cow :: Borrowed ( attr) , import_parent) )
2740
+ } else {
2741
+ None
2742
2742
}
2743
2743
}
2744
- hir:: Attribute :: Parsed ( ..) if is_inline => {
2745
- attrs. push ( ( Cow :: Owned ( attr) , import_parent) ) ;
2746
- }
2747
- _ => { }
2744
+ hir:: Attribute :: Parsed ( ..) if is_inline => Some ( ( Cow :: Borrowed ( attr) , import_parent) ) ,
2745
+ _ => None ,
2748
2746
}
2749
- }
2747
+ } )
2750
2748
}
2751
2749
2752
2750
fn clean_maybe_renamed_item < ' tcx > (
0 commit comments