Skip to content

Commit 4602d92

Browse files
committed
Rename Features::active_features.
The word "active" is currently used in two different and confusing ways: - `ACTIVE_FEATURES` actually means "available unstable features" - `Features::active_features` actually means "features declared in the crate's code", which can include feature within `ACTIVE_FEATURES` but also others. (This is also distinct from "enabled" features which includes declared features but also some edition-specific features automatically enabled depending on the edition in use.) This commit changes the `Features::active_features` to `Features::declared_features` which actually matches its meaning. Likewise, `Features::active` becomes `Features::declared`.
1 parent b229be0 commit 4602d92

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

compiler/rustc_expand/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
155155
if let Some(Feature { since, .. }) = ACCEPTED_FEATURES.iter().find(|f| name == f.name) {
156156
let since = Some(Symbol::intern(since));
157157
features.declared_lang_features.push((name, mi.span(), since));
158-
features.active_features.insert(name);
158+
features.declared_features.insert(name);
159159
continue;
160160
}
161161

@@ -173,14 +173,14 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
173173
if let Some(f) = ACTIVE_FEATURES.iter().find(|f| name == f.name) {
174174
f.set(&mut features);
175175
features.declared_lang_features.push((name, mi.span(), None));
176-
features.active_features.insert(name);
176+
features.declared_features.insert(name);
177177
continue;
178178
}
179179

180180
// Otherwise, the feature is unknown. Record it at a lib feature.
181181
// It will be checked later.
182182
features.declared_lib_features.push((name, mi.span()));
183-
features.active_features.insert(name);
183+
features.declared_features.insert(name);
184184
}
185185
}
186186

compiler/rustc_feature/src/active.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ macro_rules! declare_features {
6060
pub declared_lang_features: Vec<(Symbol, Span, Option<Symbol>)>,
6161
/// `#![feature]` attrs for non-language (library) features.
6262
pub declared_lib_features: Vec<(Symbol, Span)>,
63-
/// Features enabled for this crate.
64-
pub active_features: FxHashSet<Symbol>,
63+
/// `declared_lang_features` + `declared_lib_features`.
64+
pub declared_features: FxHashSet<Symbol>,
65+
/// Individual features (unstable only).
6566
$(
6667
$(#[doc = $doc])*
6768
pub $feature: bool
@@ -73,12 +74,14 @@ macro_rules! declare_features {
7374
$(f(stringify!($feature), self.$feature);)+
7475
}
7576

76-
/// Is the given feature active?
77-
pub fn active(&self, feature: Symbol) -> bool {
78-
self.active_features.contains(&feature)
77+
/// Is the given feature explicitly declared, i.e. named in a
78+
/// `#![feature(...)]` within the code?
79+
pub fn declared(&self, feature: Symbol) -> bool {
80+
self.declared_features.contains(&feature)
7981
}
8082

81-
/// Is the given feature enabled?
83+
/// Is the given feature enabled, i.e. declared or automatically
84+
/// enabled due to the edition?
8285
///
8386
/// Panics if the symbol doesn't correspond to a declared feature.
8487
pub fn enabled(&self, feature: Symbol) -> bool {

compiler/rustc_middle/src/middle/stability.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,14 +448,14 @@ impl<'tcx> TyCtxt<'tcx> {
448448
debug!("stability: skipping span={:?} since it is internal", span);
449449
return EvalResult::Allow;
450450
}
451-
if self.features().active(feature) {
451+
if self.features().declared(feature) {
452452
return EvalResult::Allow;
453453
}
454454

455455
// If this item was previously part of a now-stabilized feature which is still
456456
// active (i.e. the user hasn't removed the attribute for the stabilized feature
457457
// yet) then allow use of this item.
458-
if let Some(implied_by) = implied_by && self.features().active(implied_by) {
458+
if let Some(implied_by) = implied_by && self.features().declared(implied_by) {
459459
return EvalResult::Allow;
460460
}
461461

@@ -532,7 +532,7 @@ impl<'tcx> TyCtxt<'tcx> {
532532
debug!("body stability: skipping span={:?} since it is internal", span);
533533
return EvalResult::Allow;
534534
}
535-
if self.features().active(feature) {
535+
if self.features().declared(feature) {
536536
return EvalResult::Allow;
537537
}
538538

src/tools/clippy/clippy_lints/src/manual_float_methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods {
8585
if !in_external_macro(cx.sess(), expr.span)
8686
&& (
8787
matches!(cx.tcx.constness(cx.tcx.hir().enclosing_body_owner(expr.hir_id)), Constness::NotConst)
88-
|| cx.tcx.features().active(sym!(const_float_classify))
88+
|| cx.tcx.features().declared(sym!(const_float_classify))
8989
) && let ExprKind::Binary(kind, lhs, rhs) = expr.kind
9090
&& let ExprKind::Binary(lhs_kind, lhs_lhs, lhs_rhs) = lhs.kind
9191
&& let ExprKind::Binary(rhs_kind, rhs_lhs, rhs_rhs) = rhs.kind

0 commit comments

Comments
 (0)