]> git.lizzy.rs Git - rust.git/blob - src/librustc_feature/lib.rs
move Stability to rustc_feature
[rust.git] / src / librustc_feature / lib.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
19 use std::fmt;
20 use std::num::NonZeroU32;
21 use syntax_pos::{Span, edition::Edition, symbol::Symbol};
22
23 #[derive(Clone, Copy)]
24 pub enum State {
25     Accepted,
26     Active { set: fn(&mut Features, Span) },
27     Removed { reason: Option<&'static str> },
28     Stabilized { reason: Option<&'static str> },
29 }
30
31 impl fmt::Debug for State {
32     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33         match self {
34             State::Accepted { .. } => write!(f, "accepted"),
35             State::Active { .. } => write!(f, "active"),
36             State::Removed { .. } => write!(f, "removed"),
37             State::Stabilized { .. } => write!(f, "stabilized"),
38         }
39     }
40 }
41
42 #[derive(Debug, Clone)]
43 pub struct Feature {
44     pub state: State,
45     pub name: Symbol,
46     pub since: &'static str,
47     issue: Option<u32>,  // FIXME: once #58732 is done make this an Option<NonZeroU32>
48     pub edition: Option<Edition>,
49     description: &'static str,
50 }
51
52 impl Feature {
53     // FIXME(Centril): privatize again.
54     pub fn issue(&self) -> Option<NonZeroU32> {
55         self.issue.and_then(|i| NonZeroU32::new(i))
56     }
57 }
58
59 #[derive(Copy, Clone, Debug)]
60 pub enum Stability {
61     Unstable,
62     // First argument is tracking issue link; second argument is an optional
63     // help message, which defaults to "remove this attribute".
64     Deprecated(&'static str, Option<&'static str>),
65 }
66
67 pub use accepted::ACCEPTED_FEATURES;
68 pub use active::{ACTIVE_FEATURES, Features, INCOMPLETE_FEATURES};
69 pub use removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES};