diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs index d43c6fec7d5..762198887cf 100644 --- a/compiler/rustc_expand/src/config.rs +++ b/compiler/rustc_expand/src/config.rs @@ -167,6 +167,7 @@ fn active_features_up_to(edition: Edition) -> impl Iterator impl Iterator)>, /// `#![feature]` attrs for non-language (library) features. pub declared_lib_features: Vec<(Symbol, Span)>, + /// Features enabled for this crate. + pub active_features: FxHashSet, $( $(#[doc = $doc])* pub $feature: bool @@ -58,6 +61,11 @@ pub fn walk_feature_fields(&self, mut f: impl FnMut(&str, bool)) { $(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 enabled? /// /// Panics if the symbol doesn't correspond to a declared feature. diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index ff19c33d8e8..35b2796f972 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -6,7 +6,7 @@ use crate::ty::{self, DefIdTree, TyCtxt}; use rustc_ast::NodeId; use rustc_attr::{self as attr, ConstStability, Deprecation, Stability}; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::FxHashMap; use rustc_errors::{Applicability, Diagnostic}; use rustc_feature::GateIssue; use rustc_hir as hir; @@ -66,9 +66,6 @@ pub struct Index { /// Maps for each crate whether it is part of the staged API. pub staged_api: FxHashMap, - - /// Features enabled for this crate. - pub active_features: FxHashSet, } impl Index { @@ -423,7 +420,7 @@ pub fn eval_stability( debug!("stability: skipping span={:?} since it is internal", span); return EvalResult::Allow; } - if self.stability().active_features.contains(&feature) { + if self.features().active(feature) { return EvalResult::Allow; } diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index df3853d8744..592dc8ce27f 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -663,19 +663,8 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index { stab_map: Default::default(), const_stab_map: Default::default(), depr_map: Default::default(), - active_features: Default::default(), }; - let active_lib_features = &tcx.features().declared_lib_features; - let active_lang_features = &tcx.features().declared_lang_features; - - // Put the active features into a map for quick lookup. - index.active_features = active_lib_features - .iter() - .map(|&(s, ..)| s) - .chain(active_lang_features.iter().map(|&(s, ..)| s)) - .collect(); - { let mut annotator = Annotator { tcx,