@@ -24,6 +24,7 @@ use rustc_session::Session;
24
24
use rustc_span:: edition:: { Edition , ALL_EDITIONS } ;
25
25
use rustc_span:: symbol:: { sym, Symbol } ;
26
26
use rustc_span:: Span ;
27
+ use thin_vec:: ThinVec ;
27
28
28
29
/// A folder that strips out items that do not belong in the current configuration.
29
30
pub struct StripUnconfigured < ' a > {
@@ -54,6 +55,14 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
54
55
} )
55
56
}
56
57
58
+ fn feature_list ( attr : & Attribute ) -> ThinVec < ast:: NestedMetaItem > {
59
+ if attr. has_name ( sym:: feature) && let Some ( list) = attr. meta_item_list ( ) {
60
+ list
61
+ } else {
62
+ ThinVec :: new ( )
63
+ }
64
+ }
65
+
57
66
let mut features = Features :: default ( ) ;
58
67
let mut edition_enabled_features = FxHashMap :: default ( ) ;
59
68
let crate_edition = sess. edition ( ) ;
@@ -81,15 +90,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
81
90
// - E.g. enable `test_2018_feature` if the crate edition is 2015 but
82
91
// `rust_2018_preview` is present
83
92
for attr in krate_attrs {
84
- if !attr. has_name ( sym:: feature) {
85
- continue ;
86
- }
87
-
88
- let Some ( list) = attr. meta_item_list ( ) else {
89
- continue ;
90
- } ;
91
-
92
- for mi in list {
93
+ for mi in feature_list ( attr) {
93
94
if !mi. is_word ( ) {
94
95
continue ;
95
96
}
@@ -114,15 +115,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
114
115
115
116
// Process all features declared in the code.
116
117
for attr in krate_attrs {
117
- if !attr. has_name ( sym:: feature) {
118
- continue ;
119
- }
120
-
121
- let Some ( list) = attr. meta_item_list ( ) else {
122
- continue ;
123
- } ;
124
-
125
- for mi in list {
118
+ for mi in feature_list ( attr) {
126
119
let name = match mi. ident ( ) {
127
120
Some ( ident) if mi. is_word ( ) => ident. name ,
128
121
Some ( ident) => {
0 commit comments