]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/feature_gate/mod.rs
c4418c0f0f632b26cf26ec0e1e900ca0868d76c8
[rust.git] / src / libsyntax / feature_gate / mod.rs
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 crate::{edition::Edition, symbol::Symbol};
22 use std::fmt;
23 use std::num::NonZeroU32;
24 use syntax_pos::Span;
25
26 #[derive(Clone, Copy)]
27 pub enum State {
28     Accepted,
29     Active { set: fn(&mut Features, Span) },
30     Removed { reason: Option<&'static str> },
31     Stabilized { reason: Option<&'static str> },
32 }
33
34 impl fmt::Debug for State {
35     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36         match self {
37             State::Accepted { .. } => write!(f, "accepted"),
38             State::Active { .. } => write!(f, "active"),
39             State::Removed { .. } => write!(f, "removed"),
40             State::Stabilized { .. } => write!(f, "stabilized"),
41         }
42     }
43 }
44
45 #[derive(Debug, Clone)]
46 pub struct Feature {
47     state: State,
48     name: Symbol,
49     since: &'static str,
50     issue: Option<u32>,  // FIXME: once #58732 is done make this an Option<NonZeroU32>
51     edition: Option<Edition>,
52     description: &'static str,
53 }
54
55 impl Feature {
56     fn issue(&self) -> Option<NonZeroU32> {
57         self.issue.and_then(|i| NonZeroU32::new(i))
58     }
59 }
60
61 pub use active::{Features, INCOMPLETE_FEATURES};
62 pub use builtin_attrs::{
63     AttributeGate, AttributeType, GatedCfg,
64     BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP,
65     deprecated_attributes, is_builtin_attr,  is_builtin_attr_name,
66 };
67 pub use check::{
68     check_crate, check_attribute, get_features, feature_err, emit_feature_err,
69     Stability, GateIssue, UnstableFeatures,
70     EXPLAIN_STMT_ATTR_SYNTAX, EXPLAIN_UNSIZED_TUPLE_COERCION,
71 };