Skip to content

Commit 4870ee6

Browse files
committed
Move the set of features to the features query.
1 parent bfb2856 commit 4870ee6

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

compiler/rustc_expand/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ fn get_features(
167167
if let Some(Feature { since, .. }) = ACCEPTED_FEATURES.iter().find(|f| name == f.name) {
168168
let since = Some(Symbol::intern(since));
169169
features.declared_lang_features.push((name, mi.span(), since));
170+
features.active_features.insert(name);
170171
continue;
171172
}
172173

@@ -187,10 +188,12 @@ fn get_features(
187188
if let Some(f) = ACTIVE_FEATURES.iter().find(|f| name == f.name) {
188189
f.set(&mut features, mi.span());
189190
features.declared_lang_features.push((name, mi.span(), None));
191+
features.active_features.insert(name);
190192
continue;
191193
}
192194

193195
features.declared_lib_features.push((name, mi.span()));
196+
features.active_features.insert(name);
194197
}
195198
}
196199

compiler/rustc_feature/src/active.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use super::{to_nonzero, Feature, State};
44

5+
use rustc_data_structures::fx::FxHashSet;
56
use rustc_span::edition::Edition;
67
use rustc_span::symbol::{sym, Symbol};
78
use rustc_span::Span;
@@ -47,6 +48,8 @@ macro_rules! declare_features {
4748
pub declared_lang_features: Vec<(Symbol, Span, Option<Symbol>)>,
4849
/// `#![feature]` attrs for non-language (library) features.
4950
pub declared_lib_features: Vec<(Symbol, Span)>,
51+
/// Features enabled for this crate.
52+
pub active_features: FxHashSet<Symbol>,
5053
$(
5154
$(#[doc = $doc])*
5255
pub $feature: bool
@@ -58,6 +61,11 @@ macro_rules! declare_features {
5861
$(f(stringify!($feature), self.$feature);)+
5962
}
6063

64+
/// Is the given feature active?
65+
pub fn active(&self, feature: Symbol) -> bool {
66+
self.active_features.contains(&feature)
67+
}
68+
6169
/// Is the given feature enabled?
6270
///
6371
/// Panics if the symbol doesn't correspond to a declared feature.

compiler/rustc_middle/src/middle/stability.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use self::StabilityLevel::*;
66
use crate::ty::{self, DefIdTree, TyCtxt};
77
use rustc_ast::NodeId;
88
use rustc_attr::{self as attr, ConstStability, Deprecation, Stability};
9-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
9+
use rustc_data_structures::fx::FxHashMap;
1010
use rustc_errors::{Applicability, DiagnosticBuilder};
1111
use rustc_feature::GateIssue;
1212
use rustc_hir as hir;
@@ -66,9 +66,6 @@ pub struct Index<'tcx> {
6666

6767
/// Maps for each crate whether it is part of the staged API.
6868
pub staged_api: FxHashMap<CrateNum, bool>,
69-
70-
/// Features enabled for this crate.
71-
pub active_features: FxHashSet<Symbol>,
7269
}
7370

7471
impl<'tcx> Index<'tcx> {
@@ -423,7 +420,7 @@ impl<'tcx> TyCtxt<'tcx> {
423420
debug!("stability: skipping span={:?} since it is internal", span);
424421
return EvalResult::Allow;
425422
}
426-
if self.stability().active_features.contains(&feature) {
423+
if self.features().active(feature) {
427424
return EvalResult::Allow;
428425
}
429426

compiler/rustc_passes/src/stability.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -665,19 +665,8 @@ fn stability_index<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> Index<'tcx> {
665665
stab_map: Default::default(),
666666
const_stab_map: Default::default(),
667667
depr_map: Default::default(),
668-
active_features: Default::default(),
669668
};
670669

671-
let active_lib_features = &tcx.features().declared_lib_features;
672-
let active_lang_features = &tcx.features().declared_lang_features;
673-
674-
// Put the active features into a map for quick lookup.
675-
index.active_features = active_lib_features
676-
.iter()
677-
.map(|&(s, ..)| s)
678-
.chain(active_lang_features.iter().map(|&(s, ..)| s))
679-
.collect();
680-
681670
{
682671
let mut annotator = Annotator {
683672
tcx,

0 commit comments

Comments
 (0)