diff options
Diffstat (limited to 'compiler/rustc_feature/src')
| -rw-r--r-- | compiler/rustc_feature/src/lib.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_feature/src/unstable.rs | 47 |
2 files changed, 36 insertions, 15 deletions
diff --git a/compiler/rustc_feature/src/lib.rs b/compiler/rustc_feature/src/lib.rs index 216793485e5..9f42d3ec45c 100644 --- a/compiler/rustc_feature/src/lib.rs +++ b/compiler/rustc_feature/src/lib.rs @@ -135,4 +135,6 @@ pub use builtin_attrs::{ is_valid_for_get_attr, }; pub use removed::REMOVED_LANG_FEATURES; -pub use unstable::{Features, INCOMPATIBLE_FEATURES, UNSTABLE_LANG_FEATURES}; +pub use unstable::{ + EnabledLangFeature, EnabledLibFeature, Features, INCOMPATIBLE_FEATURES, UNSTABLE_LANG_FEATURES, +}; diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 8182eb1e973..f29bae61124 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -36,35 +36,54 @@ macro_rules! status_to_enum { #[derive(Clone, Default, Debug)] pub struct Features { /// `#![feature]` attrs for language features, for error reporting. - enabled_lang_features: Vec<(Symbol, Span, Option<Symbol>)>, + enabled_lang_features: Vec<EnabledLangFeature>, /// `#![feature]` attrs for non-language (library) features. - enabled_lib_features: Vec<(Symbol, Span)>, + enabled_lib_features: Vec<EnabledLibFeature>, /// `enabled_lang_features` + `enabled_lib_features`. enabled_features: FxHashSet<Symbol>, } +/// Information about an enabled language feature. +#[derive(Debug, Copy, Clone)] +pub struct EnabledLangFeature { + /// Name of the feature gate guarding the language feature. + pub gate_name: Symbol, + /// Span of the `#[feature(...)]` attribute. + pub attr_sp: Span, + /// If the lang feature is stable, the version number when it was stabilized. + pub stable_since: Option<Symbol>, +} + +/// Information abhout an enabled library feature. +#[derive(Debug, Copy, Clone)] +pub struct EnabledLibFeature { + pub gate_name: Symbol, + pub attr_sp: Span, +} + impl Features { /// `since` should be set for stable features that are nevertheless enabled with a `#[feature]` /// attribute, indicating since when they are stable. - pub fn set_enabled_lang_feature(&mut self, name: Symbol, span: Span, since: Option<Symbol>) { - self.enabled_lang_features.push((name, span, since)); - self.enabled_features.insert(name); + pub fn set_enabled_lang_feature(&mut self, lang_feat: EnabledLangFeature) { + self.enabled_lang_features.push(lang_feat); + self.enabled_features.insert(lang_feat.gate_name); } - pub fn set_enabled_lib_feature(&mut self, name: Symbol, span: Span) { - self.enabled_lib_features.push((name, span)); - self.enabled_features.insert(name); + pub fn set_enabled_lib_feature(&mut self, lib_feat: EnabledLibFeature) { + self.enabled_lib_features.push(lib_feat); + self.enabled_features.insert(lib_feat.gate_name); } - /// Returns a list of triples with: - /// - feature gate name - /// - the span of the `#[feature]` attribute - /// - (for already stable features) the version since which it is stable - pub fn enabled_lang_features(&self) -> &Vec<(Symbol, Span, Option<Symbol>)> { + /// Returns a list of [`EnabledLangFeature`] with info about: + /// + /// - Feature gate name. + /// - The span of the `#[feature]` attribute. + /// - For stable language features, version info for when it was stabilized. + pub fn enabled_lang_features(&self) -> &Vec<EnabledLangFeature> { &self.enabled_lang_features } - pub fn enabled_lib_features(&self) -> &Vec<(Symbol, Span)> { + pub fn enabled_lib_features(&self) -> &Vec<EnabledLibFeature> { &self.enabled_lib_features } |
