@@ -980,18 +980,24 @@ pub(crate) struct Module {
980
980
}
981
981
982
982
pub ( crate ) trait AttributesExt {
983
- type AttributeIterator < ' a > : Iterator < Item = ast:: MetaItemInner >
984
- where
985
- Self : ' a ;
986
983
type Attributes < ' a > : Iterator < Item = & ' a hir:: Attribute >
987
984
where
988
985
Self : ' a ;
989
986
990
- fn lists ( & self , name : Symbol ) -> Self :: AttributeIterator < ' _ > ;
991
-
992
987
fn iter ( & self ) -> Self :: Attributes < ' _ > ;
993
988
}
994
989
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
+
995
1001
pub fn extract_cfg_from_attrs < A : AttributesExt + ?Sized > (
996
1002
attrs : & A ,
997
1003
tcx : TyCtxt < ' _ > ,
@@ -1066,7 +1072,7 @@ pub fn extract_cfg_from_attrs<A: AttributesExt + ?Sized>(
1066
1072
1067
1073
// treat #[target_feature(enable = "feat")] attributes as if they were
1068
1074
// #[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) {
1070
1076
if attr. has_name ( sym:: enable) {
1071
1077
if attr. value_str ( ) . is_some ( ) {
1072
1078
// Clone `enable = "feat"`, change to `target_feature = "feat"`.
@@ -1085,38 +1091,19 @@ pub fn extract_cfg_from_attrs<A: AttributesExt + ?Sized>(
1085
1091
}
1086
1092
1087
1093
impl AttributesExt for [ hir:: Attribute ] {
1088
- type AttributeIterator < ' a > = impl Iterator < Item = ast:: MetaItemInner > + ' a ;
1089
1094
type Attributes < ' a > = impl Iterator < Item = & ' a hir:: Attribute > + ' a ;
1090
1095
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
-
1098
1096
fn iter ( & self ) -> Self :: Attributes < ' _ > {
1099
1097
self . iter ( )
1100
1098
}
1101
1099
}
1102
1100
1103
1101
impl AttributesExt for [ ( Cow < ' _ , hir:: Attribute > , Option < DefId > ) ] {
1104
- type AttributeIterator < ' a >
1105
- = impl Iterator < Item = ast:: MetaItemInner > + ' a
1106
- where
1107
- Self : ' a ;
1108
1102
type Attributes < ' a >
1109
1103
= impl Iterator < Item = & ' a hir:: Attribute > + ' a
1110
1104
where
1111
1105
Self : ' a ;
1112
1106
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
-
1120
1107
fn iter ( & self ) -> Self :: Attributes < ' _ > {
1121
1108
self . iter ( ) . map ( move |( attr, _) | match attr {
1122
1109
Cow :: Borrowed ( attr) => * attr,
@@ -1188,7 +1175,7 @@ pub(crate) struct Attributes {
1188
1175
1189
1176
impl Attributes {
1190
1177
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)
1192
1179
}
1193
1180
1194
1181
pub ( crate ) fn has_doc_flag ( & self , flag : Symbol ) -> bool {
@@ -1255,7 +1242,9 @@ impl Attributes {
1255
1242
pub ( crate ) fn get_doc_aliases ( & self ) -> Box < [ Symbol ] > {
1256
1243
let mut aliases = FxIndexSet :: default ( ) ;
1257
1244
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
+ {
1259
1248
if let Some ( values) = attr. meta_item_list ( ) {
1260
1249
for l in values {
1261
1250
if let Some ( lit) = l. lit ( )
0 commit comments