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 {
230230/// ```
231231/// #![feature(cfg_select)]
232232///
233- /// let _some_string = cfg_select! {{
233+ /// let _some_string = cfg_select! {
234234/// unix => { "With great power comes great electricity bills" }
235235/// _ => { "Behind every successful diet is an unwatched pizza" }
236- /// }} ;
236+ /// };
237237/// ```
238238 #[ unstable ( feature = "cfg_select" , issue = "115585" ) ]
239239#[ 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 */
259243}
260244
261245/// 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() {
4848fn cfg_select_basic ( ) {
4949 cfg_select ! {
5050 target_pointer_width = "64" => { fn f0_( ) -> bool { true } }
51+ _ => { }
5152 }
5253
5354 cfg_select ! {
5455 unix => { fn f1_( ) -> bool { true } }
55- any ( target_os = "macos" , target_os = "linux" ) => { fn f1_( ) -> bool { false } }
56+ _ => { fn f1_( ) -> bool { false } }
5657 }
5758
5859 cfg_select ! {
@@ -70,6 +71,8 @@ fn cfg_select_basic() {
7071
7172 #[ cfg( unix) ]
7273 assert ! ( f1_( ) ) ;
74+ #[ cfg( not( unix) ) ]
75+ assert ! ( !f1_( ) ) ;
7376
7477 #[ cfg( target_pointer_width = "32" ) ]
7578 assert ! ( !f2_( ) ) ;
@@ -183,6 +186,12 @@ fn _accepts_expressions() -> i32 {
183186 }
184187}
185188
189+ fn _accepts_only_wildcard ( ) -> i32 {
190+ cfg_select ! {
191+ _ => { 1 }
192+ }
193+ }
194+
186195// The current implementation expands to a macro call, which allows the use of expression
187196// statements.
188197fn _allows_stmt_expr_attributes ( ) {
@@ -195,12 +204,12 @@ fn _allows_stmt_expr_attributes() {
195204}
196205
197206fn _expression ( ) {
198- let _ = cfg_select ! ( {
207+ let _ = cfg_select ! (
199208 windows => {
200209 " XP"
201210 }
202211 _ => {
203212 ""
204213 }
205- } ) ;
214+ ) ;
206215}
You can’t perform that action at this time.
0 commit comments