Skip to content

Commit 3a231bf

Browse files
committed
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: #115585 [1]: #115585 (comment)
1 parent ce36a96 commit 3a231bf

File tree

12 files changed

+49
-39
lines changed

12 files changed

+49
-39
lines changed

compiler/rustc_codegen_cranelift/patches/0027-coretests-128bit-atomic-operations.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ index 1e336bf..35e6f54 100644
1717
@@ -2,5 +2,4 @@
1818
// tidy-alphabetical-start
1919
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
20-
#![cfg_attr(test, feature(cfg_match))]
20+
#![cfg_attr(test, feature(cfg_select))]
2121
#![feature(alloc_layout_extra)]
2222
#![feature(array_chunks)]
2323
diff --git a/tests/atomic.rs b/tests/atomic.rs

compiler/rustc_codegen_gcc/patches/0022-core-Disable-not-compiling-tests.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ index a4a7946..ecfe43f 100644
3737
// tidy-alphabetical-start
3838
+#![cfg(test)]
3939
#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
40-
#![cfg_attr(test, feature(cfg_match))]
40+
#![cfg_attr(test, feature(cfg_select))]
4141
#![feature(alloc_layout_extra)]
4242
--
4343
2.47.1

compiler/rustc_data_structures/src/flock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ cfg_match! {
2929
}
3030

3131
#[cfg(not(bootstrap))]
32-
cfg_match! {
32+
cfg_select! {
3333
target_os = "linux" => {
3434
mod linux;
3535
use linux as imp;

compiler/rustc_data_structures/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#![allow(internal_features)]
1111
#![allow(rustc::default_hash_types)]
1212
#![allow(rustc::potential_query_instability)]
13+
#![cfg_attr(bootstrap, feature(cfg_match))]
14+
#![cfg_attr(not(bootstrap), feature(cfg_select))]
1315
#![deny(unsafe_op_in_unsafe_fn)]
1416
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1517
#![doc(rust_logo)]
@@ -19,7 +21,6 @@
1921
#![feature(ascii_char_variants)]
2022
#![feature(assert_matches)]
2123
#![feature(auto_traits)]
22-
#![feature(cfg_match)]
2324
#![feature(core_intrinsics)]
2425
#![feature(dropck_eyepatch)]
2526
#![feature(extend_one)]

compiler/rustc_data_structures/src/profiling.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ cfg_match! {
923923
}
924924

925925
#[cfg(not(bootstrap))]
926-
cfg_match! {
926+
cfg_select! {
927927
windows => {
928928
pub fn get_resident_set_size() -> Option<usize> {
929929
use std::mem;

compiler/rustc_span/src/analyze_source_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ cfg_match! {
155155
}
156156

157157
#[cfg(not(bootstrap))]
158-
cfg_match! {
158+
cfg_select! {
159159
any(target_arch = "x86", target_arch = "x86_64") => {
160160
fn analyze_source_file_dispatch(
161161
src: &str,

compiler/rustc_span/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
1818
// tidy-alphabetical-start
1919
#![allow(internal_features)]
20+
#![cfg_attr(bootstrap, feature(cfg_match))]
21+
#![cfg_attr(not(bootstrap), feature(cfg_select))]
2022
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
2123
#![doc(rust_logo)]
2224
#![feature(array_windows)]
23-
#![feature(cfg_match)]
2425
#![feature(core_io_borrowed_buf)]
2526
#![feature(hash_set_entry)]
2627
#![feature(if_let_guard)]

library/core/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,12 @@ pub mod autodiff {
251251
#[unstable(feature = "contracts", issue = "128044")]
252252
pub mod contracts;
253253

254+
#[cfg(bootstrap)]
254255
#[unstable(feature = "cfg_match", issue = "115585")]
255256
pub use crate::macros::cfg_match;
257+
#[cfg(not(bootstrap))]
258+
#[unstable(feature = "cfg_select", issue = "115585")]
259+
pub use crate::macros::cfg_select;
256260

257261
#[macro_use]
258262
mod internal_macros;

library/core/src/macros/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ pub macro cfg_match {
299299
/// # Example
300300
///
301301
/// ```
302-
/// #![feature(cfg_match)]
302+
/// #![feature(cfg_select)]
303303
///
304-
/// cfg_match! {
304+
/// cfg_select! {
305305
/// unix => {
306306
/// fn foo() { /* unix specific functionality */ }
307307
/// }
@@ -317,19 +317,19 @@ pub macro cfg_match {
317317
/// If desired, it is possible to return expressions through the use of surrounding braces:
318318
///
319319
/// ```
320-
/// #![feature(cfg_match)]
320+
/// #![feature(cfg_select)]
321321
///
322-
/// let _some_string = cfg_match! {{
322+
/// let _some_string = cfg_select! {{
323323
/// unix => { "With great power comes great electricity bills" }
324324
/// _ => { "Behind every successful diet is an unwatched pizza" }
325325
/// }};
326326
/// ```
327327
#[cfg(not(bootstrap))]
328-
#[unstable(feature = "cfg_match", issue = "115585")]
329-
#[rustc_diagnostic_item = "cfg_match"]
330-
pub macro cfg_match {
328+
#[unstable(feature = "cfg_select", issue = "115585")]
329+
#[rustc_diagnostic_item = "cfg_select"]
330+
pub macro cfg_select {
331331
({ $($tt:tt)* }) => {{
332-
cfg_match! { $($tt)* }
332+
cfg_select! { $($tt)* }
333333
}},
334334
(_ => { $($output:tt)* }) => {
335335
$($output)*
@@ -339,10 +339,10 @@ pub macro cfg_match {
339339
$($( $rest:tt )+)?
340340
) => {
341341
#[cfg($cfg)]
342-
cfg_match! { _ => $output }
342+
cfg_select! { _ => $output }
343343
$(
344344
#[cfg(not($cfg))]
345-
cfg_match! { $($rest)+ }
345+
cfg_select! { $($rest)+ }
346346
)?
347347
},
348348
}

library/coretests/tests/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// tidy-alphabetical-start
22
#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
3-
#![cfg_attr(test, feature(cfg_match))]
3+
#![cfg_attr(test, feature(cfg_select))]
44
#![feature(alloc_layout_extra)]
55
#![feature(array_chunks)]
66
#![feature(array_ptr_get)]

library/coretests/tests/macros.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait Trait {
99
struct Struct;
1010

1111
impl Trait for Struct {
12-
cfg_match! {
12+
cfg_select! {
1313
feature = "blah" => {
1414
fn blah(&self) {
1515
unimplemented!();
@@ -45,22 +45,22 @@ fn matches_leading_pipe() {
4545
}
4646

4747
#[test]
48-
fn cfg_match_basic() {
49-
cfg_match! {
48+
fn cfg_select_basic() {
49+
cfg_select! {
5050
target_pointer_width = "64" => { fn f0_() -> bool { true }}
5151
}
5252

53-
cfg_match! {
53+
cfg_select! {
5454
unix => { fn f1_() -> bool { true } }
5555
any(target_os = "macos", target_os = "linux") => { fn f1_() -> bool { false }}
5656
}
5757

58-
cfg_match! {
58+
cfg_select! {
5959
target_pointer_width = "32" => { fn f2_() -> bool { false } }
6060
target_pointer_width = "64" => { fn f2_() -> bool { true } }
6161
}
6262

63-
cfg_match! {
63+
cfg_select! {
6464
target_pointer_width = "16" => { fn f3_() -> i32 { 1 } }
6565
_ => { fn f3_() -> i32 { 2 }}
6666
}
@@ -81,8 +81,8 @@ fn cfg_match_basic() {
8181
}
8282

8383
#[test]
84-
fn cfg_match_debug_assertions() {
85-
cfg_match! {
84+
fn cfg_select_debug_assertions() {
85+
cfg_select! {
8686
debug_assertions => {
8787
assert!(cfg!(debug_assertions));
8888
assert_eq!(4, 2+2);
@@ -96,8 +96,8 @@ fn cfg_match_debug_assertions() {
9696

9797
#[cfg(target_pointer_width = "64")]
9898
#[test]
99-
fn cfg_match_no_duplication_on_64() {
100-
cfg_match! {
99+
fn cfg_select_no_duplication_on_64() {
100+
cfg_select! {
101101
windows => {
102102
fn foo() {}
103103
}
@@ -112,34 +112,34 @@ fn cfg_match_no_duplication_on_64() {
112112
}
113113

114114
#[test]
115-
fn cfg_match_options() {
116-
cfg_match! {
115+
fn cfg_select_options() {
116+
cfg_select! {
117117
test => {
118118
use core::option::Option as Option2;
119119
fn works1() -> Option2<u32> { Some(1) }
120120
}
121121
_ => { fn works1() -> Option<u32> { None } }
122122
}
123123

124-
cfg_match! {
124+
cfg_select! {
125125
feature = "foo" => { fn works2() -> bool { false } }
126126
test => { fn works2() -> bool { true } }
127127
_ => { fn works2() -> bool { false } }
128128
}
129129

130-
cfg_match! {
130+
cfg_select! {
131131
feature = "foo" => { fn works3() -> bool { false } }
132132
_ => { fn works3() -> bool { true } }
133133
}
134134

135-
cfg_match! {
135+
cfg_select! {
136136
test => {
137137
use core::option::Option as Option3;
138138
fn works4() -> Option3<u32> { Some(1) }
139139
}
140140
}
141141

142-
cfg_match! {
142+
cfg_select! {
143143
feature = "foo" => { fn works5() -> bool { false } }
144144
test => { fn works5() -> bool { true } }
145145
}
@@ -152,8 +152,8 @@ fn cfg_match_options() {
152152
}
153153

154154
#[test]
155-
fn cfg_match_two_functions() {
156-
cfg_match! {
155+
fn cfg_select_two_functions() {
156+
cfg_select! {
157157
target_pointer_width = "64" => {
158158
fn foo1() {}
159159
fn bar1() {}
@@ -177,7 +177,7 @@ fn cfg_match_two_functions() {
177177
}
178178

179179
fn _accepts_expressions() -> i32 {
180-
cfg_match! {
180+
cfg_select! {
181181
unix => { 1 }
182182
_ => { 2 }
183183
}
@@ -188,14 +188,14 @@ fn _accepts_expressions() -> i32 {
188188
fn _allows_stmt_expr_attributes() {
189189
let one = 1;
190190
let two = 2;
191-
cfg_match! {
191+
cfg_select! {
192192
unix => { one * two; }
193193
_ => { one + two; }
194194
}
195195
}
196196

197197
fn _expression() {
198-
let _ = cfg_match!({
198+
let _ = cfg_select!({
199199
windows => {
200200
" XP"
201201
}

library/std/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,12 @@ mod panicking;
690690
#[allow(dead_code, unused_attributes, fuzzy_provenance_casts, unsafe_op_in_unsafe_fn)]
691691
mod backtrace_rs;
692692

693+
#[cfg(bootstrap)]
693694
#[unstable(feature = "cfg_match", issue = "115585")]
694695
pub use core::cfg_match;
696+
#[cfg(not(bootstrap))]
697+
#[unstable(feature = "cfg_select", issue = "115585")]
698+
pub use core::cfg_select;
695699
#[unstable(
696700
feature = "concat_bytes",
697701
issue = "87555",

0 commit comments

Comments
 (0)