]> git.proxmox.com Git - rustc.git/blame - src/libsyntax/feature_gate/mod.rs
New upstream version 1.40.0+dfsg1
[rustc.git] / src / libsyntax / feature_gate / mod.rs
CommitLineData
e1599b0c
XL
1//! # Feature gating
2//!
3//! This module implements the gating necessary for preventing certain compiler
4//! features from being used by default. This module will crawl a pre-expanded
5//! AST to ensure that there are no features which are used that are not
6//! enabled.
7//!
8//! Features are enabled in programs via the crate-level attributes of
9//! `#![feature(...)]` with a comma-separated list of features.
10//!
11//! For the purpose of future feature-tracking, once code for detection of feature
12//! gate usage is added, *do not remove it again* even once the feature
13//! becomes stable.
14
15mod accepted;
16mod removed;
17mod active;
18mod builtin_attrs;
19mod check;
20
21use std::fmt;
22use crate::{edition::Edition, symbol::Symbol};
23use syntax_pos::Span;
24
25#[derive(Clone, Copy)]
26pub enum State {
27 Accepted,
28 Active { set: fn(&mut Features, Span) },
29 Removed { reason: Option<&'static str> },
30 Stabilized { reason: Option<&'static str> },
31}
32
33impl fmt::Debug for State {
34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 match self {
36 State::Accepted { .. } => write!(f, "accepted"),
37 State::Active { .. } => write!(f, "active"),
38 State::Removed { .. } => write!(f, "removed"),
39 State::Stabilized { .. } => write!(f, "stabilized"),
40 }
41 }
42}
43
44#[derive(Debug, Clone)]
45pub struct Feature {
46 state: State,
47 name: Symbol,
48 since: &'static str,
49 issue: Option<u32>,
50 edition: Option<Edition>,
51 description: &'static str,
52}
53
54pub use active::{Features, INCOMPLETE_FEATURES};
55pub use builtin_attrs::{
56 AttributeGate, AttributeType, GatedCfg,
57 BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP,
58 deprecated_attributes, is_builtin_attr, is_builtin_attr_name,
59};
60pub use check::{
e74abb32 61 check_crate, check_attribute, get_features, feature_err, emit_feature_err,
e1599b0c
XL
62 Stability, GateIssue, UnstableFeatures,
63 EXPLAIN_STMT_ATTR_SYNTAX, EXPLAIN_UNSIZED_TUPLE_COERCION,
64};