]>
Commit | Line | Data |
---|---|---|
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 | ||
15 | mod accepted; | |
16 | mod removed; | |
17 | mod active; | |
18 | mod builtin_attrs; | |
19 | mod check; | |
20 | ||
21 | use std::fmt; | |
22 | use crate::{edition::Edition, symbol::Symbol}; | |
23 | use syntax_pos::Span; | |
24 | ||
25 | #[derive(Clone, Copy)] | |
26 | pub 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 | ||
33 | impl 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)] | |
45 | pub 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 | ||
54 | pub use active::{Features, INCOMPLETE_FEATURES}; | |
55 | pub 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 | }; | |
60 | pub 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 | }; |