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`.
This commit is contained in:
Nicholas Nethercote 2023-10-05 16:08:07 +11:00
parent b229be0127
commit 4602d9257d
4 changed files with 16 additions and 13 deletions

View File

@ -155,7 +155,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
if let Some(Feature { since, .. }) = ACCEPTED_FEATURES.iter().find(|f| name == f.name) {
let since = Some(Symbol::intern(since));
features.declared_lang_features.push((name, mi.span(), since));
features.active_features.insert(name);
features.declared_features.insert(name);
continue;
}
@ -173,14 +173,14 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
if let Some(f) = ACTIVE_FEATURES.iter().find(|f| name == f.name) {
f.set(&mut features);
features.declared_lang_features.push((name, mi.span(), None));
features.active_features.insert(name);
features.declared_features.insert(name);
continue;
}
// Otherwise, the feature is unknown. Record it at a lib feature.
// It will be checked later.
features.declared_lib_features.push((name, mi.span()));
features.active_features.insert(name);
features.declared_features.insert(name);
}
}

View File

@ -60,8 +60,9 @@ macro_rules! declare_features {
pub declared_lang_features: Vec<(Symbol, Span, Option<Symbol>)>,
/// `#![feature]` attrs for non-language (library) features.
pub declared_lib_features: Vec<(Symbol, Span)>,
/// Features enabled for this crate.
pub active_features: FxHashSet<Symbol>,
/// `declared_lang_features` + `declared_lib_features`.
pub declared_features: FxHashSet<Symbol>,
/// Individual features (unstable only).
$(
$(#[doc = $doc])*
pub $feature: bool
@ -73,12 +74,14 @@ macro_rules! declare_features {
$(f(stringify!($feature), self.$feature);)+
}
/// Is the given feature active?
pub fn active(&self, feature: Symbol) -> bool {
self.active_features.contains(&feature)
/// Is the given feature explicitly declared, i.e. named in a
/// `#![feature(...)]` within the code?
pub fn declared(&self, feature: Symbol) -> bool {
self.declared_features.contains(&feature)
}
/// Is the given feature enabled?
/// Is the given feature enabled, i.e. declared or automatically
/// enabled due to the edition?
///
/// Panics if the symbol doesn't correspond to a declared feature.
pub fn enabled(&self, feature: Symbol) -> bool {

View File

@ -448,14 +448,14 @@ impl<'tcx> TyCtxt<'tcx> {
debug!("stability: skipping span={:?} since it is internal", span);
return EvalResult::Allow;
}
if self.features().active(feature) {
if self.features().declared(feature) {
return EvalResult::Allow;
}
// If this item was previously part of a now-stabilized feature which is still
// active (i.e. the user hasn't removed the attribute for the stabilized feature
// yet) then allow use of this item.
if let Some(implied_by) = implied_by && self.features().active(implied_by) {
if let Some(implied_by) = implied_by && self.features().declared(implied_by) {
return EvalResult::Allow;
}
@ -532,7 +532,7 @@ impl<'tcx> TyCtxt<'tcx> {
debug!("body stability: skipping span={:?} since it is internal", span);
return EvalResult::Allow;
}
if self.features().active(feature) {
if self.features().declared(feature) {
return EvalResult::Allow;
}

View File

@ -85,7 +85,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods {
if !in_external_macro(cx.sess(), expr.span)
&& (
matches!(cx.tcx.constness(cx.tcx.hir().enclosing_body_owner(expr.hir_id)), Constness::NotConst)
|| cx.tcx.features().active(sym!(const_float_classify))
|| cx.tcx.features().declared(sym!(const_float_classify))
) && let ExprKind::Binary(kind, lhs, rhs) = expr.kind
&& let ExprKind::Binary(lhs_kind, lhs_lhs, lhs_rhs) = lhs.kind
&& let ExprKind::Binary(rhs_kind, rhs_lhs, rhs_rhs) = rhs.kind