2018-11-26 20:59:49 -06:00
|
|
|
//! # Feature gating
|
2013-10-02 20:10:16 -05:00
|
|
|
//!
|
2015-04-16 02:18:29 -05:00
|
|
|
//! This module implements the gating necessary for preventing certain compiler
|
2013-10-02 20:10:16 -05: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 12:29:42 -05:00
|
|
|
//! `#![feature(...)]` with a comma-separated list of features.
|
2015-01-14 21:27:45 -06: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 16:31:06 -06:00
|
|
|
|
2019-08-20 11:40:53 -05:00
|
|
|
mod accepted;
|
2019-08-20 11:41:18 -05:00
|
|
|
mod removed;
|
2019-08-20 11:50:33 -05:00
|
|
|
mod active;
|
2019-08-22 16:48:08 -05:00
|
|
|
|
2019-11-11 11:33:30 -06:00
|
|
|
use std::fmt;
|
|
|
|
use std::num::NonZeroU32;
|
2019-11-29 17:23:38 -06:00
|
|
|
use syntax_pos::{Span, edition::Edition, symbol::Symbol};
|
2019-08-24 10:50:21 -05:00
|
|
|
|
|
|
|
#[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 {
|
2019-11-29 17:23:38 -06:00
|
|
|
pub state: State,
|
|
|
|
pub name: Symbol,
|
|
|
|
pub since: &'static str,
|
2019-11-11 11:33:30 -06:00
|
|
|
issue: Option<u32>, // FIXME: once #58732 is done make this an Option<NonZeroU32>
|
2019-11-29 17:23:38 -06:00
|
|
|
pub edition: Option<Edition>,
|
2019-08-24 10:50:21 -05:00
|
|
|
description: &'static str,
|
|
|
|
}
|
|
|
|
|
2019-11-11 11:33:30 -06:00
|
|
|
impl Feature {
|
2019-11-29 17:23:38 -06:00
|
|
|
// FIXME(Centril): privatize again.
|
|
|
|
pub fn issue(&self) -> Option<NonZeroU32> {
|
2019-11-11 11:33:30 -06:00
|
|
|
self.issue.and_then(|i| NonZeroU32::new(i))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-29 17:23:38 -06:00
|
|
|
pub use accepted::ACCEPTED_FEATURES;
|
|
|
|
pub use active::{ACTIVE_FEATURES, Features, INCOMPLETE_FEATURES};
|
|
|
|
pub use removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES};
|