File tree Expand file tree Collapse file tree 2 files changed +17
-24
lines changed Expand file tree Collapse file tree 2 files changed +17
-24
lines changed Original file line number Diff line number Diff line change @@ -230,32 +230,16 @@ pub macro assert_matches {
230
230
/// ```
231
231
/// #![feature(cfg_select)]
232
232
///
233
- /// let _some_string = cfg_select! {{
233
+ /// let _some_string = cfg_select! {
234
234
/// unix => { "With great power comes great electricity bills" }
235
235
/// _ => { "Behind every successful diet is an unwatched pizza" }
236
- /// }} ;
236
+ /// };
237
237
/// ```
238
238
#[ unstable ( feature = "cfg_select" , issue = "115585" ) ]
239
239
#[ rustc_diagnostic_item = "cfg_select" ]
240
- #[ rustc_macro_transparency = "semitransparent" ]
241
- pub macro cfg_select {
242
- ( { $( $tt: tt) * } ) => { {
243
- $crate:: cfg_select! { $( $tt) * }
244
- } } ,
245
- ( _ => { $( $output: tt) * } ) => {
246
- $( $output) *
247
- } ,
248
- (
249
- $cfg: meta => $output: tt
250
- $( $( $rest: tt ) +) ?
251
- ) => {
252
- #[ cfg( $cfg) ]
253
- $crate:: cfg_select! { _ => $output }
254
- $(
255
- #[ cfg( not( $cfg) ) ]
256
- $crate:: cfg_select! { $( $rest) + }
257
- ) ?
258
- } ,
240
+ #[ rustc_builtin_macro]
241
+ pub macro cfg_select( $( $tt: tt) * ) {
242
+ /* compiler built-in */
259
243
}
260
244
261
245
/// Asserts that a boolean expression is `true` at runtime.
Original file line number Diff line number Diff line change @@ -48,11 +48,12 @@ fn matches_leading_pipe() {
48
48
fn cfg_select_basic ( ) {
49
49
cfg_select ! {
50
50
target_pointer_width = "64" => { fn f0_( ) -> bool { true } }
51
+ _ => { }
51
52
}
52
53
53
54
cfg_select ! {
54
55
unix => { fn f1_( ) -> bool { true } }
55
- any ( target_os = "macos" , target_os = "linux" ) => { fn f1_( ) -> bool { false } }
56
+ _ => { fn f1_( ) -> bool { false } }
56
57
}
57
58
58
59
cfg_select ! {
@@ -70,6 +71,8 @@ fn cfg_select_basic() {
70
71
71
72
#[ cfg( unix) ]
72
73
assert ! ( f1_( ) ) ;
74
+ #[ cfg( not( unix) ) ]
75
+ assert ! ( !f1_( ) ) ;
73
76
74
77
#[ cfg( target_pointer_width = "32" ) ]
75
78
assert ! ( !f2_( ) ) ;
@@ -183,6 +186,12 @@ fn _accepts_expressions() -> i32 {
183
186
}
184
187
}
185
188
189
+ fn _accepts_only_wildcard ( ) -> i32 {
190
+ cfg_select ! {
191
+ _ => { 1 }
192
+ }
193
+ }
194
+
186
195
// The current implementation expands to a macro call, which allows the use of expression
187
196
// statements.
188
197
fn _allows_stmt_expr_attributes ( ) {
@@ -195,12 +204,12 @@ fn _allows_stmt_expr_attributes() {
195
204
}
196
205
197
206
fn _expression ( ) {
198
- let _ = cfg_select ! ( {
207
+ let _ = cfg_select ! (
199
208
windows => {
200
209
" XP"
201
210
}
202
211
_ => {
203
212
""
204
213
}
205
- } ) ;
214
+ ) ;
206
215
}
You can’t perform that action at this time.
0 commit comments