about summary refs log tree commit diff
path: root/library/coretests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-07-13 18:34:13 +0000
committerbors <bors@rust-lang.org>2025-07-13 18:34:13 +0000
commite9182f195b8505c87c4bd055b9f6e114ccda0981 (patch)
treeb570601233e295aa02c88e5392f60d17b59ec5db /library/coretests
parent56835d7ac14da9f966e1ff39fd9ffd2e29b764d1 (diff)
parent3689b80b75bb400e740897ec83e64be332098c0d (diff)
downloadrust-e9182f195b8505c87c4bd055b9f6e114ccda0981.tar.gz
rust-e9182f195b8505c87c4bd055b9f6e114ccda0981.zip
Auto merge of #143461 - folkertdev:cfg-select-builtin-macro, r=petrochenkov
make `cfg_select` a builtin macro

tracking issue: https://github.com/rust-lang/rust/issues/115585

This parses mostly the same as the `macro cfg_select` version, except:

1. wrapping in double brackets is no longer supported (or needed): `cfg_select {{ /* ... */ }}` is now rejected.
2. in an expression context, the rhs is no longer wrapped in a block, so that this now works:
  ```rust
  fn main() {
      println!(cfg_select! {
          unix => { "foo" }
          _ => { "bar" }
      });
  }
  ```
3. a single wildcard rule is now supported: `cfg_select { _ => 1 }` now works

I've also added an error if none of the rules evaluate to true, and warnings for any arms that follow the `_` wildcard rule.

cc `@traviscross` if I'm missing any feature that should/should not be included
r? `@petrochenkov` for the macro logic details
Diffstat (limited to 'library/coretests')
-rw-r--r--library/coretests/tests/macros.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/library/coretests/tests/macros.rs b/library/coretests/tests/macros.rs
index d220e628d73..1c6aa90dfbc 100644
--- a/library/coretests/tests/macros.rs
+++ b/library/coretests/tests/macros.rs
@@ -48,11 +48,12 @@ fn matches_leading_pipe() {
 fn cfg_select_basic() {
     cfg_select! {
         target_pointer_width = "64" => { fn f0_() -> bool { true }}
+        _ => {}
     }
 
     cfg_select! {
         unix => { fn f1_() -> bool { true } }
-        any(target_os = "macos", target_os = "linux") => { fn f1_() -> bool { false }}
+        _ => { fn f1_() -> bool { false }}
     }
 
     cfg_select! {
@@ -70,6 +71,8 @@ fn cfg_select_basic() {
 
     #[cfg(unix)]
     assert!(f1_());
+    #[cfg(not(unix))]
+    assert!(!f1_());
 
     #[cfg(target_pointer_width = "32")]
     assert!(!f2_());
@@ -183,6 +186,12 @@ fn _accepts_expressions() -> i32 {
     }
 }
 
+fn _accepts_only_wildcard() -> i32 {
+    cfg_select! {
+        _ => { 1 }
+    }
+}
+
 // The current implementation expands to a macro call, which allows the use of expression
 // statements.
 fn _allows_stmt_expr_attributes() {
@@ -195,12 +204,12 @@ fn _allows_stmt_expr_attributes() {
 }
 
 fn _expression() {
-    let _ = cfg_select!({
+    let _ = cfg_select!(
         windows => {
             " XP"
         }
         _ => {
             ""
         }
-    });
+    );
 }