1
- use std:: borrow:: Cow ;
2
1
use std:: hash:: Hash ;
3
2
use std:: path:: PathBuf ;
4
3
use std:: sync:: { Arc , OnceLock as OnceCell } ;
@@ -479,7 +478,7 @@ impl Item {
479
478
name,
480
479
kind,
481
480
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 ) ,
483
482
)
484
483
}
485
484
@@ -979,27 +978,19 @@ pub(crate) struct Module {
979
978
pub ( crate ) span : Span ,
980
979
}
981
980
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 ,
992
983
name : Symbol ,
993
- ) -> impl Iterator < Item = ast:: MetaItemInner > + use < ' _ , A > {
984
+ ) -> impl Iterator < Item = ast:: MetaItemInner > + use < ' a , I > {
994
985
attrs
995
- . iter ( )
986
+ . into_iter ( )
996
987
. filter ( move |attr| attr. has_name ( name) )
997
988
. filter_map ( ast:: attr:: AttributeExt :: meta_item_list)
998
989
. flatten ( )
999
990
}
1000
991
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 ,
1003
994
tcx : TyCtxt < ' _ > ,
1004
995
hidden_cfg : & FxHashSet < Cfg > ,
1005
996
) -> Option < Arc < Cfg > > {
@@ -1018,7 +1009,7 @@ pub fn extract_cfg_from_attrs<A: AttributesExt + ?Sized>(
1018
1009
1019
1010
let mut cfg = if doc_cfg_active || doc_auto_cfg_active {
1020
1011
let mut doc_cfg = attrs
1021
- . iter ( )
1012
+ . clone ( )
1022
1013
. filter ( |attr| attr. has_name ( sym:: doc) )
1023
1014
. flat_map ( |attr| attr. meta_item_list ( ) . unwrap_or_default ( ) )
1024
1015
. filter ( |attr| attr. has_name ( sym:: cfg) )
@@ -1031,7 +1022,7 @@ pub fn extract_cfg_from_attrs<A: AttributesExt + ?Sized>(
1031
1022
// If there is no `doc(cfg())`, then we retrieve the `cfg()` attributes (because
1032
1023
// `doc(cfg())` overrides `cfg()`).
1033
1024
attrs
1034
- . iter ( )
1025
+ . clone ( )
1035
1026
. filter ( |attr| attr. has_name ( sym:: cfg) )
1036
1027
. filter_map ( |attr| single ( attr. meta_item_list ( ) ?) )
1037
1028
. 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>(
1043
1034
Cfg :: True
1044
1035
} ;
1045
1036
1046
- for attr in attrs. iter ( ) {
1037
+ for attr in attrs. clone ( ) {
1047
1038
// #[doc]
1048
1039
if attr. doc_str ( ) . is_none ( ) && attr. has_name ( sym:: doc) {
1049
1040
// #[doc(...)]
@@ -1090,28 +1081,6 @@ pub fn extract_cfg_from_attrs<A: AttributesExt + ?Sized>(
1090
1081
if cfg == Cfg :: True { None } else { Some ( Arc :: new ( cfg) ) }
1091
1082
}
1092
1083
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
-
1115
1084
pub ( crate ) trait NestedAttributesExt {
1116
1085
/// Returns `true` if the attribute list contains a specific `word`
1117
1086
fn has_word ( self , word : Symbol ) -> bool
0 commit comments