Skip to content

Commit 12b80a4

Browse files
committed
Move the set of features to the features query.
1 parent 6cbc6c3 commit 12b80a4

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
@@ -165,6 +165,7 @@ fn get_features(
165165
if let Some(Feature { since, .. }) = ACCEPTED_FEATURES.iter().find(|f| name == f.name) {
166166
let since = Some(Symbol::intern(since));
167167
features.declared_lang_features.push((name, mi.span(), since));
168+
features.active_features.insert(name);
168169
continue;
169170
}
170171

@@ -185,10 +186,12 @@ fn get_features(
185186
if let Some(f) = ACTIVE_FEATURES.iter().find(|f| name == f.name) {
186187
f.set(&mut features, mi.span());
187188
features.declared_lang_features.push((name, mi.span(), None));
189+
features.active_features.insert(name);
188190
continue;
189191
}
190192

191193
features.declared_lib_features.push((name, mi.span()));
194+
features.active_features.insert(name);
192195
}
193196
}
194197

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, Diagnostic};
1111
use rustc_feature::GateIssue;
1212
use rustc_hir as hir;
@@ -66,9 +66,6 @@ pub struct Index {
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 Index {
@@ -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
@@ -663,19 +663,8 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
663663
stab_map: Default::default(),
664664
const_stab_map: Default::default(),
665665
depr_map: Default::default(),
666-
active_features: Default::default(),
667666
};
668667

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

0 commit comments

Comments
 (0)