From fbcf7d415b806e494a582c108f609abd43b3ef6b Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 16 Jan 2022 16:25:47 +0100 Subject: [PATCH] Move the set of features to the `features` query. --- compiler/rustc_expand/src/config.rs | 3 +++ compiler/rustc_feature/src/active.rs | 8 ++++++++ compiler/rustc_middle/src/middle/stability.rs | 7 ++----- compiler/rustc_passes/src/stability.rs | 11 ----------- 4 files changed, 13 insertions(+), 16 deletions(-) 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 get_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); continue; } @@ -187,10 +188,12 @@ fn get_features( if let Some(f) = ACTIVE_FEATURES.iter().find(|f| name == f.name) { f.set(&mut features, mi.span()); features.declared_lang_features.push((name, mi.span(), None)); + features.active_features.insert(name); continue; } features.declared_lib_features.push((name, mi.span())); + features.active_features.insert(name); } } diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 1d9d16e85cb..1f7dc769512 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -2,6 +2,7 @@ use super::{to_nonzero, Feature, State}; +use rustc_data_structures::fx::FxHashSet; use rustc_span::edition::Edition; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; @@ -47,6 +48,8 @@ macro_rules! declare_features { pub declared_lang_features: Vec<(Symbol, Span, Option)>, /// `#![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 @@ 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 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 @@ pub use self::StabilityLevel::*; 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 @@ impl<'tcx> TyCtxt<'tcx> { 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,