1- use std:: borrow:: Cow ;
21use std:: hash:: Hash ;
32use std:: path:: PathBuf ;
43use std:: sync:: { Arc , OnceLock as OnceCell } ;
@@ -479,7 +478,7 @@ impl Item {
479478 name,
480479 kind,
481480 Attributes :: from_hir ( hir_attrs) ,
482- extract_cfg_from_attrs ( hir_attrs, cx. tcx , & cx. cache . hidden_cfg ) ,
481+ extract_cfg_from_attrs ( hir_attrs. iter ( ) , cx. tcx , & cx. cache . hidden_cfg ) ,
483482 )
484483 }
485484
@@ -979,27 +978,19 @@ pub(crate) struct Module {
979978 pub ( crate ) span : Span ,
980979}
981980
982- pub ( crate ) trait AttributesExt {
983- type Attributes < ' a > : Iterator < Item = & ' a hir:: Attribute >
984- where
985- Self : ' a ;
986-
987- fn iter ( & self ) -> Self :: Attributes < ' _ > ;
988- }
989-
990- pub fn hir_attr_lists < A : AttributesExt + ?Sized > (
991- attrs : & A ,
981+ pub ( crate ) fn hir_attr_lists < ' a , I : IntoIterator < Item = & ' a hir:: Attribute > > (
982+ attrs : I ,
992983 name : Symbol ,
993- ) -> impl Iterator < Item = ast:: MetaItemInner > + use < ' _ , A > {
984+ ) -> impl Iterator < Item = ast:: MetaItemInner > + use < ' a , I > {
994985 attrs
995- . iter ( )
986+ . into_iter ( )
996987 . filter ( move |attr| attr. has_name ( name) )
997988 . filter_map ( ast:: attr:: AttributeExt :: meta_item_list)
998989 . flatten ( )
999990}
1000991
1001- pub fn extract_cfg_from_attrs < A : AttributesExt + ? Sized > (
1002- attrs : & A ,
992+ pub ( crate ) fn extract_cfg_from_attrs < ' a , I : Iterator < Item = & ' a hir :: Attribute > + Clone > (
993+ attrs : I ,
1003994 tcx : TyCtxt < ' _ > ,
1004995 hidden_cfg : & FxHashSet < Cfg > ,
1005996) -> Option < Arc < Cfg > > {
@@ -1018,7 +1009,7 @@ pub fn extract_cfg_from_attrs<A: AttributesExt + ?Sized>(
10181009
10191010 let mut cfg = if doc_cfg_active || doc_auto_cfg_active {
10201011 let mut doc_cfg = attrs
1021- . iter ( )
1012+ . clone ( )
10221013 . filter ( |attr| attr. has_name ( sym:: doc) )
10231014 . flat_map ( |attr| attr. meta_item_list ( ) . unwrap_or_default ( ) )
10241015 . filter ( |attr| attr. has_name ( sym:: cfg) )
@@ -1031,7 +1022,7 @@ pub fn extract_cfg_from_attrs<A: AttributesExt + ?Sized>(
10311022 // If there is no `doc(cfg())`, then we retrieve the `cfg()` attributes (because
10321023 // `doc(cfg())` overrides `cfg()`).
10331024 attrs
1034- . iter ( )
1025+ . clone ( )
10351026 . filter ( |attr| attr. has_name ( sym:: cfg) )
10361027 . filter_map ( |attr| single ( attr. meta_item_list ( ) ?) )
10371028 . filter_map ( |attr| Cfg :: parse_without ( attr. meta_item ( ) ?, hidden_cfg) . ok ( ) . flatten ( ) )
@@ -1043,7 +1034,7 @@ pub fn extract_cfg_from_attrs<A: AttributesExt + ?Sized>(
10431034 Cfg :: True
10441035 } ;
10451036
1046- for attr in attrs. iter ( ) {
1037+ for attr in attrs. clone ( ) {
10471038 // #[doc]
10481039 if attr. doc_str ( ) . is_none ( ) && attr. has_name ( sym:: doc) {
10491040 // #[doc(...)]
@@ -1090,28 +1081,6 @@ pub fn extract_cfg_from_attrs<A: AttributesExt + ?Sized>(
10901081 if cfg == Cfg :: True { None } else { Some ( Arc :: new ( cfg) ) }
10911082}
10921083
1093- impl AttributesExt for [ hir:: Attribute ] {
1094- type Attributes < ' a > = impl Iterator < Item = & ' a hir:: Attribute > + ' a ;
1095-
1096- fn iter ( & self ) -> Self :: Attributes < ' _ > {
1097- self . iter ( )
1098- }
1099- }
1100-
1101- impl AttributesExt for [ ( Cow < ' _ , hir:: Attribute > , Option < DefId > ) ] {
1102- type Attributes < ' a >
1103- = impl Iterator < Item = & ' a hir:: Attribute > + ' a
1104- where
1105- Self : ' a ;
1106-
1107- fn iter ( & self ) -> Self :: Attributes < ' _ > {
1108- self . iter ( ) . map ( move |( attr, _) | match attr {
1109- Cow :: Borrowed ( attr) => * attr,
1110- Cow :: Owned ( attr) => attr,
1111- } )
1112- }
1113- }
1114-
11151084pub ( crate ) trait NestedAttributesExt {
11161085 /// Returns `true` if the attribute list contains a specific `word`
11171086 fn has_word ( self , word : Symbol ) -> bool
0 commit comments