From 3a231bf4ac55de78063a81dc00504564956bc567 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 18 Feb 2025 00:27:30 +0000 Subject: [PATCH] Rename `cfg_match!` to `cfg_select!` At [1] it was pointed out that `cfg_match!` syntax does not actually align well with match syntax, which is a possible source of confusion. The comment points out that usage is instead more similar to ecosystem `select!` macros. Rename `cfg_match!` to `cfg_select!` to match this. Tracking issue: https://github.com/rust-lang/rust/issues/115585 [1]: https://github.com/rust-lang/rust/issues/115585#issuecomment-2346307605 --- ...7-coretests-128bit-atomic-operations.patch | 2 +- ...022-core-Disable-not-compiling-tests.patch | 2 +- compiler/rustc_data_structures/src/flock.rs | 2 +- compiler/rustc_data_structures/src/lib.rs | 3 +- .../rustc_data_structures/src/profiling.rs | 2 +- .../rustc_span/src/analyze_source_file.rs | 2 +- compiler/rustc_span/src/lib.rs | 3 +- library/core/src/lib.rs | 4 ++ library/core/src/macros/mod.rs | 20 ++++----- library/coretests/tests/lib.rs | 2 +- library/coretests/tests/macros.rs | 42 +++++++++---------- library/std/src/lib.rs | 4 ++ 12 files changed, 49 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/patches/0027-coretests-128bit-atomic-operations.patch b/compiler/rustc_codegen_cranelift/patches/0027-coretests-128bit-atomic-operations.patch index 4a06dc3f7ef85..bd2e08d9e91ca 100644 --- a/compiler/rustc_codegen_cranelift/patches/0027-coretests-128bit-atomic-operations.patch +++ b/compiler/rustc_codegen_cranelift/patches/0027-coretests-128bit-atomic-operations.patch @@ -17,7 +17,7 @@ index 1e336bf..35e6f54 100644 @@ -2,5 +2,4 @@ // tidy-alphabetical-start -#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))] - #![cfg_attr(test, feature(cfg_match))] + #![cfg_attr(test, feature(cfg_select))] #![feature(alloc_layout_extra)] #![feature(array_chunks)] diff --git a/tests/atomic.rs b/tests/atomic.rs diff --git a/compiler/rustc_codegen_gcc/patches/0022-core-Disable-not-compiling-tests.patch b/compiler/rustc_codegen_gcc/patches/0022-core-Disable-not-compiling-tests.patch index 70e3e2ba7fee1..6350c41cf91bb 100644 --- a/compiler/rustc_codegen_gcc/patches/0022-core-Disable-not-compiling-tests.patch +++ b/compiler/rustc_codegen_gcc/patches/0022-core-Disable-not-compiling-tests.patch @@ -37,7 +37,7 @@ index a4a7946..ecfe43f 100644 // tidy-alphabetical-start +#![cfg(test)] #![cfg_attr(target_has_atomic = "128", feature(integer_atomics))] - #![cfg_attr(test, feature(cfg_match))] + #![cfg_attr(test, feature(cfg_select))] #![feature(alloc_layout_extra)] -- 2.47.1 diff --git a/compiler/rustc_data_structures/src/flock.rs b/compiler/rustc_data_structures/src/flock.rs index 292a33d56469a..46a44fd67ee65 100644 --- a/compiler/rustc_data_structures/src/flock.rs +++ b/compiler/rustc_data_structures/src/flock.rs @@ -29,7 +29,7 @@ cfg_match! { } #[cfg(not(bootstrap))] -cfg_match! { +cfg_select! { target_os = "linux" => { mod linux; use linux as imp; diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 66d3834d85784..96eb580556444 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -10,6 +10,8 @@ #![allow(internal_features)] #![allow(rustc::default_hash_types)] #![allow(rustc::potential_query_instability)] +#![cfg_attr(bootstrap, feature(cfg_match))] +#![cfg_attr(not(bootstrap), feature(cfg_select))] #![deny(unsafe_op_in_unsafe_fn)] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(rust_logo)] @@ -19,7 +21,6 @@ #![feature(ascii_char_variants)] #![feature(assert_matches)] #![feature(auto_traits)] -#![feature(cfg_match)] #![feature(core_intrinsics)] #![feature(dropck_eyepatch)] #![feature(extend_one)] diff --git a/compiler/rustc_data_structures/src/profiling.rs b/compiler/rustc_data_structures/src/profiling.rs index 18e98e6c39fa9..6bd1474b7b610 100644 --- a/compiler/rustc_data_structures/src/profiling.rs +++ b/compiler/rustc_data_structures/src/profiling.rs @@ -923,7 +923,7 @@ cfg_match! { } #[cfg(not(bootstrap))] -cfg_match! { +cfg_select! { windows => { pub fn get_resident_set_size() -> Option { use std::mem; diff --git a/compiler/rustc_span/src/analyze_source_file.rs b/compiler/rustc_span/src/analyze_source_file.rs index 47cc16b623d10..477665c02bee1 100644 --- a/compiler/rustc_span/src/analyze_source_file.rs +++ b/compiler/rustc_span/src/analyze_source_file.rs @@ -155,7 +155,7 @@ cfg_match! { } #[cfg(not(bootstrap))] -cfg_match! { +cfg_select! { any(target_arch = "x86", target_arch = "x86_64") => { fn analyze_source_file_dispatch( src: &str, diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 695edc956cdb5..5b03b559f3e27 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -17,10 +17,11 @@ // tidy-alphabetical-start #![allow(internal_features)] +#![cfg_attr(bootstrap, feature(cfg_match))] +#![cfg_attr(not(bootstrap), feature(cfg_select))] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(rust_logo)] #![feature(array_windows)] -#![feature(cfg_match)] #![feature(core_io_borrowed_buf)] #![feature(hash_set_entry)] #![feature(if_let_guard)] diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 99d5af9f0ef95..54615a8d00c3f 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -251,8 +251,12 @@ pub mod autodiff { #[unstable(feature = "contracts", issue = "128044")] pub mod contracts; +#[cfg(bootstrap)] #[unstable(feature = "cfg_match", issue = "115585")] pub use crate::macros::cfg_match; +#[cfg(not(bootstrap))] +#[unstable(feature = "cfg_select", issue = "115585")] +pub use crate::macros::cfg_select; #[macro_use] mod internal_macros; diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 4c6fd196bd31c..ad09a75df894c 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -299,9 +299,9 @@ pub macro cfg_match { /// # Example /// /// ``` -/// #![feature(cfg_match)] +/// #![feature(cfg_select)] /// -/// cfg_match! { +/// cfg_select! { /// unix => { /// fn foo() { /* unix specific functionality */ } /// } @@ -317,19 +317,19 @@ pub macro cfg_match { /// If desired, it is possible to return expressions through the use of surrounding braces: /// /// ``` -/// #![feature(cfg_match)] +/// #![feature(cfg_select)] /// -/// let _some_string = cfg_match! {{ +/// let _some_string = cfg_select! {{ /// unix => { "With great power comes great electricity bills" } /// _ => { "Behind every successful diet is an unwatched pizza" } /// }}; /// ``` #[cfg(not(bootstrap))] -#[unstable(feature = "cfg_match", issue = "115585")] -#[rustc_diagnostic_item = "cfg_match"] -pub macro cfg_match { +#[unstable(feature = "cfg_select", issue = "115585")] +#[rustc_diagnostic_item = "cfg_select"] +pub macro cfg_select { ({ $($tt:tt)* }) => {{ - cfg_match! { $($tt)* } + cfg_select! { $($tt)* } }}, (_ => { $($output:tt)* }) => { $($output)* @@ -339,10 +339,10 @@ pub macro cfg_match { $($( $rest:tt )+)? ) => { #[cfg($cfg)] - cfg_match! { _ => $output } + cfg_select! { _ => $output } $( #[cfg(not($cfg))] - cfg_match! { $($rest)+ } + cfg_select! { $($rest)+ } )? }, } diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs index 1e1ff29e16151..4d1ce466627de 100644 --- a/library/coretests/tests/lib.rs +++ b/library/coretests/tests/lib.rs @@ -1,6 +1,6 @@ // tidy-alphabetical-start #![cfg_attr(target_has_atomic = "128", feature(integer_atomics))] -#![cfg_attr(test, feature(cfg_match))] +#![cfg_attr(test, feature(cfg_select))] #![feature(alloc_layout_extra)] #![feature(array_chunks)] #![feature(array_ptr_get)] diff --git a/library/coretests/tests/macros.rs b/library/coretests/tests/macros.rs index b30a40b7df28e..d220e628d7339 100644 --- a/library/coretests/tests/macros.rs +++ b/library/coretests/tests/macros.rs @@ -9,7 +9,7 @@ trait Trait { struct Struct; impl Trait for Struct { - cfg_match! { + cfg_select! { feature = "blah" => { fn blah(&self) { unimplemented!(); @@ -45,22 +45,22 @@ fn matches_leading_pipe() { } #[test] -fn cfg_match_basic() { - cfg_match! { +fn cfg_select_basic() { + cfg_select! { target_pointer_width = "64" => { fn f0_() -> bool { true }} } - cfg_match! { + cfg_select! { unix => { fn f1_() -> bool { true } } any(target_os = "macos", target_os = "linux") => { fn f1_() -> bool { false }} } - cfg_match! { + cfg_select! { target_pointer_width = "32" => { fn f2_() -> bool { false } } target_pointer_width = "64" => { fn f2_() -> bool { true } } } - cfg_match! { + cfg_select! { target_pointer_width = "16" => { fn f3_() -> i32 { 1 } } _ => { fn f3_() -> i32 { 2 }} } @@ -81,8 +81,8 @@ fn cfg_match_basic() { } #[test] -fn cfg_match_debug_assertions() { - cfg_match! { +fn cfg_select_debug_assertions() { + cfg_select! { debug_assertions => { assert!(cfg!(debug_assertions)); assert_eq!(4, 2+2); @@ -96,8 +96,8 @@ fn cfg_match_debug_assertions() { #[cfg(target_pointer_width = "64")] #[test] -fn cfg_match_no_duplication_on_64() { - cfg_match! { +fn cfg_select_no_duplication_on_64() { + cfg_select! { windows => { fn foo() {} } @@ -112,8 +112,8 @@ fn cfg_match_no_duplication_on_64() { } #[test] -fn cfg_match_options() { - cfg_match! { +fn cfg_select_options() { + cfg_select! { test => { use core::option::Option as Option2; fn works1() -> Option2 { Some(1) } @@ -121,25 +121,25 @@ fn cfg_match_options() { _ => { fn works1() -> Option { None } } } - cfg_match! { + cfg_select! { feature = "foo" => { fn works2() -> bool { false } } test => { fn works2() -> bool { true } } _ => { fn works2() -> bool { false } } } - cfg_match! { + cfg_select! { feature = "foo" => { fn works3() -> bool { false } } _ => { fn works3() -> bool { true } } } - cfg_match! { + cfg_select! { test => { use core::option::Option as Option3; fn works4() -> Option3 { Some(1) } } } - cfg_match! { + cfg_select! { feature = "foo" => { fn works5() -> bool { false } } test => { fn works5() -> bool { true } } } @@ -152,8 +152,8 @@ fn cfg_match_options() { } #[test] -fn cfg_match_two_functions() { - cfg_match! { +fn cfg_select_two_functions() { + cfg_select! { target_pointer_width = "64" => { fn foo1() {} fn bar1() {} @@ -177,7 +177,7 @@ fn cfg_match_two_functions() { } fn _accepts_expressions() -> i32 { - cfg_match! { + cfg_select! { unix => { 1 } _ => { 2 } } @@ -188,14 +188,14 @@ fn _accepts_expressions() -> i32 { fn _allows_stmt_expr_attributes() { let one = 1; let two = 2; - cfg_match! { + cfg_select! { unix => { one * two; } _ => { one + two; } } } fn _expression() { - let _ = cfg_match!({ + let _ = cfg_select!({ windows => { " XP" } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 750116c6269dd..7dc2537f94552 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -690,8 +690,12 @@ mod panicking; #[allow(dead_code, unused_attributes, fuzzy_provenance_casts, unsafe_op_in_unsafe_fn)] mod backtrace_rs; +#[cfg(bootstrap)] #[unstable(feature = "cfg_match", issue = "115585")] pub use core::cfg_match; +#[cfg(not(bootstrap))] +#[unstable(feature = "cfg_select", issue = "115585")] +pub use core::cfg_select; #[unstable( feature = "concat_bytes", issue = "87555",