Skip to content

Commit 56fd253

Browse files
committed
Add two setter functions to Features.
1 parent 95d1aa0 commit 56fd253

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

compiler/rustc_expand/src/config.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
124124
edition,
125125
});
126126
}
127-
features.declared_lang_features.push((name, mi.span(), None));
128-
features.declared_features.insert(name);
127+
features.set_declared_lang_feature(name, mi.span(), None);
129128
continue;
130129
}
131130

@@ -139,8 +138,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
139138
feature: name,
140139
edition: features_edition,
141140
});
142-
features.declared_lang_features.push((name, mi.span(), None));
143-
features.declared_features.insert(name);
141+
features.set_declared_lang_feature(name, mi.span(), None);
144142
continue;
145143
}
146144

@@ -158,8 +156,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
158156
// If the declared feature is stable, record it.
159157
if let Some(Feature { since, .. }) = ACCEPTED_FEATURES.iter().find(|f| name == f.name) {
160158
let since = Some(Symbol::intern(since));
161-
features.declared_lang_features.push((name, mi.span(), since));
162-
features.declared_features.insert(name);
159+
features.set_declared_lang_feature(name, mi.span(), since);
163160
continue;
164161
}
165162

@@ -176,15 +173,13 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
176173
// If the declared feature is unstable, record it.
177174
if let Some(f) = ACTIVE_FEATURES.iter().find(|f| name == f.name) {
178175
f.set(&mut features);
179-
features.declared_lang_features.push((name, mi.span(), None));
180-
features.declared_features.insert(name);
176+
features.set_declared_lang_feature(name, mi.span(), None);
181177
continue;
182178
}
183179

184-
// Otherwise, the feature is unknown. Record it at a lib feature.
180+
// Otherwise, the feature is unknown. Record it as a lib feature.
185181
// It will be checked later.
186-
features.declared_lib_features.push((name, mi.span()));
187-
features.declared_features.insert(name);
182+
features.set_declared_lib_feature(name, mi.span());
188183
}
189184
}
190185

compiler/rustc_feature/src/active.rs

+15
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ macro_rules! declare_features {
7070
}
7171

7272
impl Features {
73+
pub fn set_declared_lang_feature(
74+
&mut self,
75+
symbol: Symbol,
76+
span: Span,
77+
since: Option<Symbol>
78+
) {
79+
self.declared_lang_features.push((symbol, span, since));
80+
self.declared_features.insert(symbol);
81+
}
82+
83+
pub fn set_declared_lib_feature(&mut self, symbol: Symbol, span: Span) {
84+
self.declared_lib_features.push((symbol, span));
85+
self.declared_features.insert(symbol);
86+
}
87+
7388
pub fn walk_feature_fields(&self, mut f: impl FnMut(&str, bool)) {
7489
$(f(stringify!($feature), self.$feature);)+
7590
}

0 commit comments

Comments
 (0)