@@ -6,34 +6,22 @@ use syntax_pos::edition::Edition;
6
6
use syntax_pos:: Span ;
7
7
use syntax_pos:: symbol:: { Symbol , sym} ;
8
8
9
- macro_rules! set {
10
- ( $field: ident) => { {
11
- fn f( features: & mut Features , _: Span ) {
12
- features. $field = true ;
13
- }
14
- f as fn ( & mut Features , Span )
15
- } }
16
- }
17
-
18
9
macro_rules! declare_features {
19
10
( $(
20
11
$( #[ doc = $doc: tt] ) * ( active, $feature: ident, $ver: expr, $issue: expr, $edition: expr) ,
21
12
) +) => {
22
13
/// Represents active features that are currently being implemented or
23
14
/// currently being considered for addition/removal.
24
- pub const ACTIVE_FEATURES :
25
- & [ Feature ] =
26
- & [ $(
27
- // (sym::$feature, $ver, $issue, $edition, set!($feature))
28
- Feature {
29
- state: State :: Active { set: set!( $feature) } ,
30
- name: sym:: $feature,
31
- since: $ver,
32
- issue: $issue,
33
- edition: $edition,
34
- description: concat!( $( $doc, ) * ) ,
35
- }
36
- ) ,+] ;
15
+ pub const ACTIVE_FEATURES : & [ Feature ] = & [ $(
16
+ Feature {
17
+ state: State :: Active ,
18
+ name: sym:: $feature,
19
+ since: $ver,
20
+ issue: $issue,
21
+ edition: $edition,
22
+ description: concat!( $( $doc, ) * ) ,
23
+ }
24
+ ) ,+] ;
37
25
38
26
/// A set of features to be used by later passes.
39
27
#[ derive( Clone , Default ) ]
@@ -44,28 +32,43 @@ macro_rules! declare_features {
44
32
pub declared_lib_features: Vec <( Symbol , Span ) >,
45
33
$(
46
34
$( #[ doc = $doc] ) *
47
- pub $feature: bool
35
+ $feature: bool
48
36
) ,+
49
37
}
50
38
51
39
impl Features {
40
+ /// Is the given feature enabled?
41
+ ///
42
+ /// Panics if the symbol doesn't correspond to a declared feature.
43
+ pub fn on( & self , name: Symbol ) -> bool {
44
+ match name {
45
+ $( sym:: $feature => self . $feature, ) +
46
+ _ => panic!( "unknown feature `{}`" , name) ,
47
+ }
48
+ }
49
+
50
+ /// Enable the given `feature`.
51
+ ///
52
+ /// Panics if called on a non-active feature
53
+ /// or a symbol not corresponding to a declared feature.
54
+ pub fn enable( & mut self , feature: & Feature , _: Span ) {
55
+ let Feature { name, .. } = feature;
56
+ match feature. state {
57
+ State :: Active => match * name {
58
+ $( sym:: $feature => self . $feature = true , ) +
59
+ _ => panic!( "unknown feature `{}`" , name) ,
60
+ } ,
61
+ _ => panic!( "called `set` on feature `{}` which is not `active`" , name) ,
62
+ }
63
+ }
64
+
52
65
pub fn walk_feature_fields( & self , mut f: impl FnMut ( & str , bool ) ) {
53
66
$( f( stringify!( $feature) , self . $feature) ; ) +
54
67
}
55
68
}
56
69
} ;
57
70
}
58
71
59
- impl Feature {
60
- /// Sets this feature in `Features`. Panics if called on a non-active feature.
61
- pub fn set ( & self , features : & mut Features , span : Span ) {
62
- match self . state {
63
- State :: Active { set } => set ( features, span) ,
64
- _ => panic ! ( "called `set` on feature `{}` which is not `active`" , self . name)
65
- }
66
- }
67
- }
68
-
69
72
// If you change this, please modify `src/doc/unstable-book` as well.
70
73
//
71
74
// Don't ever remove anything from this list; move them to `removed.rs`.
0 commit comments