@@ -980,18 +980,24 @@ pub(crate) struct Module {
980980}
981981
982982pub ( crate ) trait AttributesExt {
983- type AttributeIterator < ' a > : Iterator < Item = ast:: MetaItemInner >
984- where
985- Self : ' a ;
986983 type Attributes < ' a > : Iterator < Item = & ' a hir:: Attribute >
987984 where
988985 Self : ' a ;
989986
990- fn lists ( & self , name : Symbol ) -> Self :: AttributeIterator < ' _ > ;
991-
992987 fn iter ( & self ) -> Self :: Attributes < ' _ > ;
993988}
994989
990+ pub fn hir_attr_lists < A : AttributesExt + ?Sized > (
991+ attrs : & A ,
992+ name : Symbol ,
993+ ) -> impl Iterator < Item = ast:: MetaItemInner > + use < ' _ , A > {
994+ attrs
995+ . iter ( )
996+ . filter ( move |attr| attr. has_name ( name) )
997+ . filter_map ( ast:: attr:: AttributeExt :: meta_item_list)
998+ . flatten ( )
999+ }
1000+
9951001pub fn extract_cfg_from_attrs < A : AttributesExt + ?Sized > (
9961002 attrs : & A ,
9971003 tcx : TyCtxt < ' _ > ,
@@ -1066,7 +1072,7 @@ pub fn extract_cfg_from_attrs<A: AttributesExt + ?Sized>(
10661072
10671073 // treat #[target_feature(enable = "feat")] attributes as if they were
10681074 // #[doc(cfg(target_feature = "feat"))] attributes as well
1069- for attr in attrs . lists ( sym:: target_feature) {
1075+ for attr in hir_attr_lists ( attrs , sym:: target_feature) {
10701076 if attr. has_name ( sym:: enable) {
10711077 if attr. value_str ( ) . is_some ( ) {
10721078 // Clone `enable = "feat"`, change to `target_feature = "feat"`.
@@ -1085,38 +1091,19 @@ pub fn extract_cfg_from_attrs<A: AttributesExt + ?Sized>(
10851091}
10861092
10871093impl AttributesExt for [ hir:: Attribute ] {
1088- type AttributeIterator < ' a > = impl Iterator < Item = ast:: MetaItemInner > + ' a ;
10891094 type Attributes < ' a > = impl Iterator < Item = & ' a hir:: Attribute > + ' a ;
10901095
1091- fn lists ( & self , name : Symbol ) -> Self :: AttributeIterator < ' _ > {
1092- self . iter ( )
1093- . filter ( move |attr| attr. has_name ( name) )
1094- . filter_map ( ast:: attr:: AttributeExt :: meta_item_list)
1095- . flatten ( )
1096- }
1097-
10981096 fn iter ( & self ) -> Self :: Attributes < ' _ > {
10991097 self . iter ( )
11001098 }
11011099}
11021100
11031101impl AttributesExt for [ ( Cow < ' _ , hir:: Attribute > , Option < DefId > ) ] {
1104- type AttributeIterator < ' a >
1105- = impl Iterator < Item = ast:: MetaItemInner > + ' a
1106- where
1107- Self : ' a ;
11081102 type Attributes < ' a >
11091103 = impl Iterator < Item = & ' a hir:: Attribute > + ' a
11101104 where
11111105 Self : ' a ;
11121106
1113- fn lists ( & self , name : Symbol ) -> Self :: AttributeIterator < ' _ > {
1114- AttributesExt :: iter ( self )
1115- . filter ( move |attr| attr. has_name ( name) )
1116- . filter_map ( hir:: Attribute :: meta_item_list)
1117- . flatten ( )
1118- }
1119-
11201107 fn iter ( & self ) -> Self :: Attributes < ' _ > {
11211108 self . iter ( ) . map ( move |( attr, _) | match attr {
11221109 Cow :: Borrowed ( attr) => * attr,
@@ -1188,7 +1175,7 @@ pub(crate) struct Attributes {
11881175
11891176impl Attributes {
11901177 pub ( crate ) fn lists ( & self , name : Symbol ) -> impl Iterator < Item = ast:: MetaItemInner > + ' _ {
1191- self . other_attrs . lists ( name)
1178+ hir_attr_lists ( & self . other_attrs [ .. ] , name)
11921179 }
11931180
11941181 pub ( crate ) fn has_doc_flag ( & self , flag : Symbol ) -> bool {
@@ -1255,7 +1242,9 @@ impl Attributes {
12551242 pub ( crate ) fn get_doc_aliases ( & self ) -> Box < [ Symbol ] > {
12561243 let mut aliases = FxIndexSet :: default ( ) ;
12571244
1258- for attr in self . other_attrs . lists ( sym:: doc) . filter ( |a| a. has_name ( sym:: alias) ) {
1245+ for attr in
1246+ hir_attr_lists ( & self . other_attrs [ ..] , sym:: doc) . filter ( |a| a. has_name ( sym:: alias) )
1247+ {
12591248 if let Some ( values) = attr. meta_item_list ( ) {
12601249 for l in values {
12611250 if let Some ( lit) = l. lit ( )
0 commit comments