2018-11-27 02:59:49 +00:00
|
|
|
//! # Feature gating
|
2013-10-02 18:10:16 -07:00
|
|
|
//!
|
2015-04-16 17:18:29 +10:00
|
|
|
//! This module implements the gating necessary for preventing certain compiler
|
2013-10-02 18:10:16 -07:00
|
|
|
//! features from being used by default. This module will crawl a pre-expanded
|
|
|
|
//! AST to ensure that there are no features which are used that are not
|
|
|
|
//! enabled.
|
|
|
|
//!
|
|
|
|
//! Features are enabled in programs via the crate-level attributes of
|
2014-06-22 10:29:42 -07:00
|
|
|
//! `#![feature(...)]` with a comma-separated list of features.
|
2015-01-14 19:27:45 -08:00
|
|
|
//!
|
|
|
|
//! For the purpose of future feature-tracking, once code for detection of feature
|
|
|
|
//! gate usage is added, *do not remove it again* even once the feature
|
|
|
|
//! becomes stable.
|
2015-02-03 23:31:06 +01:00
|
|
|
|
2019-08-20 18:40:53 +02:00
|
|
|
mod accepted;
|
2019-08-20 18:41:18 +02:00
|
|
|
mod removed;
|
2019-08-20 18:50:33 +02:00
|
|
|
mod active;
|
2019-08-22 18:32:31 +02:00
|
|
|
mod builtin_attrs;
|
2019-08-22 23:48:08 +02:00
|
|
|
mod check;
|
|
|
|
|
2019-08-24 17:50:21 +02:00
|
|
|
use std::fmt;
|
|
|
|
use crate::{edition::Edition, symbol::Symbol};
|
|
|
|
use syntax_pos::Span;
|
|
|
|
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
pub enum State {
|
|
|
|
Accepted,
|
|
|
|
Active { set: fn(&mut Features, Span) },
|
|
|
|
Removed { reason: Option<&'static str> },
|
|
|
|
Stabilized { reason: Option<&'static str> },
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Debug for State {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
match self {
|
|
|
|
State::Accepted { .. } => write!(f, "accepted"),
|
|
|
|
State::Active { .. } => write!(f, "active"),
|
|
|
|
State::Removed { .. } => write!(f, "removed"),
|
|
|
|
State::Stabilized { .. } => write!(f, "stabilized"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Feature {
|
|
|
|
state: State,
|
|
|
|
name: Symbol,
|
|
|
|
since: &'static str,
|
|
|
|
issue: Option<u32>,
|
|
|
|
edition: Option<Edition>,
|
|
|
|
description: &'static str,
|
|
|
|
}
|
|
|
|
|
2019-08-22 23:48:08 +02:00
|
|
|
pub use active::{Features, INCOMPLETE_FEATURES};
|
2019-08-22 18:32:31 +02:00
|
|
|
pub use builtin_attrs::{
|
|
|
|
AttributeGate, AttributeType, GatedCfg,
|
|
|
|
BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP,
|
|
|
|
deprecated_attributes, is_builtin_attr, is_builtin_attr_name,
|
|
|
|
};
|
2019-08-22 23:48:08 +02:00
|
|
|
pub use check::{
|
2019-09-14 21:29:59 +03:00
|
|
|
check_crate, get_features, feature_err, emit_feature_err,
|
2019-08-22 23:48:08 +02:00
|
|
|
Stability, GateIssue, UnstableFeatures,
|
|
|
|
EXPLAIN_STMT_ATTR_SYNTAX, EXPLAIN_UNSIZED_TUPLE_COERCION,
|
2019-03-21 18:40:00 +00:00
|
|
|
};
|
2019-09-14 21:29:59 +03:00
|
|
|
crate use check::check_attribute;
|