Move the set of features to the features
query.
This commit is contained in:
parent
4566094913
commit
fbcf7d415b
@ -167,6 +167,7 @@ fn active_features_up_to(edition: Edition) -> impl Iterator<Item = &'static Feat
|
|||||||
if let Some(Feature { since, .. }) = ACCEPTED_FEATURES.iter().find(|f| name == f.name) {
|
if let Some(Feature { since, .. }) = ACCEPTED_FEATURES.iter().find(|f| name == f.name) {
|
||||||
let since = Some(Symbol::intern(since));
|
let since = Some(Symbol::intern(since));
|
||||||
features.declared_lang_features.push((name, mi.span(), since));
|
features.declared_lang_features.push((name, mi.span(), since));
|
||||||
|
features.active_features.insert(name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,10 +188,12 @@ fn active_features_up_to(edition: Edition) -> impl Iterator<Item = &'static Feat
|
|||||||
if let Some(f) = ACTIVE_FEATURES.iter().find(|f| name == f.name) {
|
if let Some(f) = ACTIVE_FEATURES.iter().find(|f| name == f.name) {
|
||||||
f.set(&mut features, mi.span());
|
f.set(&mut features, mi.span());
|
||||||
features.declared_lang_features.push((name, mi.span(), None));
|
features.declared_lang_features.push((name, mi.span(), None));
|
||||||
|
features.active_features.insert(name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
features.declared_lib_features.push((name, mi.span()));
|
features.declared_lib_features.push((name, mi.span()));
|
||||||
|
features.active_features.insert(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use super::{to_nonzero, Feature, State};
|
use super::{to_nonzero, Feature, State};
|
||||||
|
|
||||||
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
@ -47,6 +48,8 @@ pub struct Features {
|
|||||||
pub declared_lang_features: Vec<(Symbol, Span, Option<Symbol>)>,
|
pub declared_lang_features: Vec<(Symbol, Span, Option<Symbol>)>,
|
||||||
/// `#![feature]` attrs for non-language (library) features.
|
/// `#![feature]` attrs for non-language (library) features.
|
||||||
pub declared_lib_features: Vec<(Symbol, Span)>,
|
pub declared_lib_features: Vec<(Symbol, Span)>,
|
||||||
|
/// Features enabled for this crate.
|
||||||
|
pub active_features: FxHashSet<Symbol>,
|
||||||
$(
|
$(
|
||||||
$(#[doc = $doc])*
|
$(#[doc = $doc])*
|
||||||
pub $feature: bool
|
pub $feature: bool
|
||||||
@ -58,6 +61,11 @@ pub fn walk_feature_fields(&self, mut f: impl FnMut(&str, bool)) {
|
|||||||
$(f(stringify!($feature), self.$feature);)+
|
$(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?
|
/// Is the given feature enabled?
|
||||||
///
|
///
|
||||||
/// Panics if the symbol doesn't correspond to a declared feature.
|
/// Panics if the symbol doesn't correspond to a declared feature.
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
use crate::ty::{self, DefIdTree, TyCtxt};
|
use crate::ty::{self, DefIdTree, TyCtxt};
|
||||||
use rustc_ast::NodeId;
|
use rustc_ast::NodeId;
|
||||||
use rustc_attr::{self as attr, ConstStability, Deprecation, Stability};
|
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_errors::{Applicability, Diagnostic};
|
||||||
use rustc_feature::GateIssue;
|
use rustc_feature::GateIssue;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
@ -66,9 +66,6 @@ pub struct Index {
|
|||||||
|
|
||||||
/// Maps for each crate whether it is part of the staged API.
|
/// Maps for each crate whether it is part of the staged API.
|
||||||
pub staged_api: FxHashMap<CrateNum, bool>,
|
pub staged_api: FxHashMap<CrateNum, bool>,
|
||||||
|
|
||||||
/// Features enabled for this crate.
|
|
||||||
pub active_features: FxHashSet<Symbol>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Index {
|
impl Index {
|
||||||
@ -423,7 +420,7 @@ pub fn eval_stability(
|
|||||||
debug!("stability: skipping span={:?} since it is internal", span);
|
debug!("stability: skipping span={:?} since it is internal", span);
|
||||||
return EvalResult::Allow;
|
return EvalResult::Allow;
|
||||||
}
|
}
|
||||||
if self.stability().active_features.contains(&feature) {
|
if self.features().active(feature) {
|
||||||
return EvalResult::Allow;
|
return EvalResult::Allow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -663,19 +663,8 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
|
|||||||
stab_map: Default::default(),
|
stab_map: Default::default(),
|
||||||
const_stab_map: Default::default(),
|
const_stab_map: Default::default(),
|
||||||
depr_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 {
|
let mut annotator = Annotator {
|
||||||
tcx,
|
tcx,
|
||||||
|
Loading…
Reference in New Issue
Block a user