@@ -110,72 +110,74 @@ pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_21;
110
110
111
111
/// Create RustFeatures struct definition, new(), and a getter for each field
112
112
macro_rules! rust_feature_def {
113
- ( $( $( #[ $attr: meta] ) * => $feature: ident; ) * ) => {
113
+ (
114
+ $( $rust_target: ident {
115
+ $( $( #[ $attr: meta] ) * => $feature: ident; ) *
116
+ } ) *
117
+ ) => {
114
118
/// Features supported by a rust target
115
119
#[ derive( Debug , Copy , Clone , Eq , PartialEq , Hash ) ]
116
120
pub struct RustFeatures {
117
- $(
121
+ $( $ (
118
122
$(
119
123
#[ $attr]
120
124
) *
121
125
pub $feature: bool ,
122
- ) *
126
+ ) * ) *
123
127
}
124
128
125
129
impl RustFeatures {
126
130
/// Gives a RustFeatures struct with all features disabled
127
131
fn new( ) -> Self {
128
132
RustFeatures {
129
- $(
133
+ $( $ (
130
134
$feature: false ,
131
- ) *
135
+ ) * ) *
132
136
}
133
137
}
134
138
}
135
- }
136
- }
137
139
138
- rust_feature_def ! (
139
- /// Untagged unions ([RFC 1444](https://github.com/rust-lang/rfcs/blob/master/text/1444-union.md))
140
- => untagged_union;
141
- /// `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202))
142
- => thiscall_abi;
143
- /// builtin impls for `Clone` ([PR](https://github.com/rust-lang/rust/pull/43690))
144
- => builtin_clone_impls;
145
- /// repr(align) https://github.com/rust-lang/rust/pull/47006
146
- => repr_align;
147
- /// associated constants https://github.com/rust-lang/rust/issues/29646
148
- => associated_const;
149
- ) ;
140
+ impl From <RustTarget > for RustFeatures {
141
+ fn from( rust_target: RustTarget ) -> Self {
142
+ let mut features = RustFeatures :: new( ) ;
150
143
151
- impl From < RustTarget > for RustFeatures {
152
- fn from ( rust_target : RustTarget ) -> Self {
153
- let mut features = RustFeatures :: new ( ) ;
154
-
155
- if rust_target >= RustTarget :: Stable_1_19 {
156
- features. untagged_union = true ;
157
- }
158
-
159
- if rust_target >= RustTarget :: Stable_1_20 {
160
- features. associated_const = true ;
161
- }
162
-
163
- if rust_target >= RustTarget :: Stable_1_21 {
164
- features. builtin_clone_impls = true ;
165
- }
166
-
167
- if rust_target >= RustTarget :: Stable_1_25 {
168
- features. repr_align = true ;
169
- }
144
+ $(
145
+ if rust_target >= RustTarget :: $rust_target {
146
+ $(
147
+ features. $feature = true ;
148
+ ) *
149
+ }
150
+ ) *
170
151
171
- if rust_target >= RustTarget :: Nightly {
172
- features . thiscall_abi = true ;
152
+ features
153
+ }
173
154
}
174
-
175
- features
176
155
}
177
156
}
178
157
158
+ rust_feature_def ! (
159
+ Stable_1_19 {
160
+ /// Untagged unions ([RFC 1444](https://github.com/rust-lang/rfcs/blob/master/text/1444-union.md))
161
+ => untagged_union;
162
+ }
163
+ Stable_1_20 {
164
+ /// associated constants ([PR](https://github.com/rust-lang/rust/pull/42809))
165
+ => associated_const;
166
+ }
167
+ Stable_1_21 {
168
+ /// builtin impls for `Clone` ([PR](https://github.com/rust-lang/rust/pull/43690))
169
+ => builtin_clone_impls;
170
+ }
171
+ Stable_1_25 {
172
+ /// repr(align) ([PR](https://github.com/rust-lang/rust/pull/47006))
173
+ => repr_align;
174
+ }
175
+ Nightly {
176
+ /// `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202))
177
+ => thiscall_abi;
178
+ }
179
+ ) ;
180
+
179
181
impl Default for RustFeatures {
180
182
fn default ( ) -> Self {
181
183
let default_rust_target: RustTarget = Default :: default ( ) ;
@@ -185,9 +187,37 @@ impl Default for RustFeatures {
185
187
186
188
#[ cfg( test) ]
187
189
mod test {
188
- #![ allow( unused_imports) ]
190
+ #![ allow( unused_imports) ]
189
191
use super :: * ;
190
192
193
+ #[ test]
194
+ fn target_features ( ) {
195
+ let f_1_0 = RustFeatures :: from ( RustTarget :: Stable_1_0 ) ;
196
+ assert ! (
197
+ !f_1_0. untagged_union
198
+ && !f_1_0. associated_const
199
+ && !f_1_0. builtin_clone_impls
200
+ && !f_1_0. repr_align
201
+ && !f_1_0. thiscall_abi
202
+ ) ;
203
+ let f_1_21 = RustFeatures :: from ( RustTarget :: Stable_1_21 ) ;
204
+ assert ! (
205
+ f_1_21. untagged_union
206
+ && f_1_21. associated_const
207
+ && f_1_21. builtin_clone_impls
208
+ && !f_1_21. repr_align
209
+ && !f_1_21. thiscall_abi
210
+ ) ;
211
+ let f_nightly = RustFeatures :: from ( RustTarget :: Nightly ) ;
212
+ assert ! (
213
+ f_nightly. untagged_union
214
+ && f_nightly. associated_const
215
+ && f_nightly. builtin_clone_impls
216
+ && f_nightly. repr_align
217
+ && f_nightly. thiscall_abi
218
+ ) ;
219
+ }
220
+
191
221
fn test_target ( target_str : & str , target : RustTarget ) {
192
222
let target_string: String = target. into ( ) ;
193
223
assert_eq ! ( target_str, target_string) ;
0 commit comments