Skip to content

Commit 999967a

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 444a627 commit 999967a

File tree

20 files changed

+60
-60
lines changed

20 files changed

+60
-60
lines changed

compiler/rustc_codegen_cranelift/patches/0027-sysroot_tests-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/coretests/tests/atomic.rs b/coretests/tests/atomic.rs

compiler/rustc_data_structures/src/flock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! green/native threading. This is just a bare-bones enough solution for
55
//! librustdoc, it is not production quality at all.
66
7-
cfg_match! {
7+
cfg_select! {
88
target_os = "linux" => {
99
mod linux;
1010
use linux as imp;

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#![feature(ascii_char_variants)]
2020
#![feature(assert_matches)]
2121
#![feature(auto_traits)]
22-
#![feature(cfg_match)]
22+
#![feature(cfg_select)]
2323
#![feature(core_intrinsics)]
2424
#![feature(dropck_eyepatch)]
2525
#![feature(extend_one)]

compiler/rustc_data_structures/src/profiling.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ fn get_thread_id() -> u32 {
860860
}
861861

862862
// Memory reporting
863-
cfg_match! {
863+
cfg_select! {
864864
windows => {
865865
pub fn get_resident_set_size() -> Option<usize> {
866866
use windows::{

compiler/rustc_span/src/analyze_source_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) fn analyze_source_file(src: &str) -> (Vec<RelativeBytePos>, Vec<Multi
2929
(lines, multi_byte_chars)
3030
}
3131

32-
cfg_match! {
32+
cfg_select! {
3333
any(target_arch = "x86", target_arch = "x86_64") => {
3434
fn analyze_source_file_dispatch(
3535
src: &str,

compiler/rustc_span/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
2121
#![doc(rust_logo)]
2222
#![feature(array_windows)]
23-
#![feature(cfg_match)]
23+
#![feature(cfg_select)]
2424
#![feature(core_io_borrowed_buf)]
2525
#![feature(hash_set_entry)]
2626
#![feature(if_let_guard)]

library/core/src/ffi/primitives.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type_alias! { "c_float.md", c_float = f32; }
3535
type_alias! { "c_double.md", c_double = f64; }
3636

3737
mod c_char_definition {
38-
crate::cfg_match! {
38+
crate::cfg_select! {
3939
// These are the targets on which c_char is unsigned. Usually the
4040
// signedness is the same for all target_os values on a given architecture
4141
// but there are some exceptions (see isSignedCharDefault() in clang).
@@ -133,7 +133,7 @@ mod c_char_definition {
133133
}
134134

135135
mod c_long_definition {
136-
crate::cfg_match! {
136+
crate::cfg_select! {
137137
any(
138138
all(target_pointer_width = "64", not(windows)),
139139
// wasm32 Linux ABI uses 64-bit long
@@ -172,7 +172,7 @@ pub type c_ptrdiff_t = isize;
172172
pub type c_ssize_t = isize;
173173

174174
mod c_int_definition {
175-
crate::cfg_match! {
175+
crate::cfg_select! {
176176
any(target_arch = "avr", target_arch = "msp430") => {
177177
pub(super) type c_int = i16;
178178
pub(super) type c_uint = u16;

library/core/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
#![feature(bigint_helper_methods)]
101101
#![feature(bstr)]
102102
#![feature(bstr_internals)]
103-
#![feature(cfg_match)]
103+
#![feature(cfg_select)]
104104
#![feature(cfg_target_has_reliable_f16_f128)]
105105
#![feature(const_carrying_mul_add)]
106106
#![feature(const_eval_select)]
@@ -235,8 +235,8 @@ pub mod autodiff {
235235
#[unstable(feature = "contracts", issue = "128044")]
236236
pub mod contracts;
237237

238-
#[unstable(feature = "cfg_match", issue = "115585")]
239-
pub use crate::macros::cfg_match;
238+
#[unstable(feature = "cfg_select", issue = "115585")]
239+
pub use crate::macros::cfg_select;
240240

241241
#[macro_use]
242242
mod internal_macros;

library/core/src/macros/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ pub macro assert_matches {
210210
/// # Example
211211
///
212212
/// ```
213-
/// #![feature(cfg_match)]
213+
/// #![feature(cfg_select)]
214214
///
215-
/// cfg_match! {
215+
/// cfg_select! {
216216
/// unix => {
217217
/// fn foo() { /* unix specific functionality */ }
218218
/// }
@@ -228,19 +228,19 @@ pub macro assert_matches {
228228
/// If desired, it is possible to return expressions through the use of surrounding braces:
229229
///
230230
/// ```
231-
/// #![feature(cfg_match)]
231+
/// #![feature(cfg_select)]
232232
///
233-
/// let _some_string = cfg_match! {{
233+
/// let _some_string = cfg_select! {{
234234
/// unix => { "With great power comes great electricity bills" }
235235
/// _ => { "Behind every successful diet is an unwatched pizza" }
236236
/// }};
237237
/// ```
238-
#[unstable(feature = "cfg_match", issue = "115585")]
239-
#[rustc_diagnostic_item = "cfg_match"]
238+
#[unstable(feature = "cfg_select", issue = "115585")]
239+
#[rustc_diagnostic_item = "cfg_select"]
240240
#[rustc_macro_transparency = "semitransparent"]
241-
pub macro cfg_match {
241+
pub macro cfg_select {
242242
({ $($tt:tt)* }) => {{
243-
$crate::cfg_match! { $($tt)* }
243+
$crate::cfg_select! { $($tt)* }
244244
}},
245245
(_ => { $($output:tt)* }) => {
246246
$($output)*
@@ -250,10 +250,10 @@ pub macro cfg_match {
250250
$($( $rest:tt )+)?
251251
) => {
252252
#[cfg($cfg)]
253-
$crate::cfg_match! { _ => $output }
253+
$crate::cfg_select! { _ => $output }
254254
$(
255255
#[cfg(not($cfg))]
256-
$crate::cfg_match! { $($rest)+ }
256+
$crate::cfg_select! { $($rest)+ }
257257
)?
258258
},
259259
}

library/core/src/num/f32.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use crate::convert::FloatToInt;
1515
use crate::num::{FpCategory, libm};
1616
use crate::panic::const_assert;
17-
use crate::{cfg_match, intrinsics, mem};
17+
use crate::{cfg_select, intrinsics, mem};
1818

1919
/// The radix or base of the internal representation of `f32`.
2020
/// Use [`f32::RADIX`] instead.
@@ -990,7 +990,7 @@ impl f32 {
990990
#[stable(feature = "num_midpoint", since = "1.85.0")]
991991
#[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
992992
pub const fn midpoint(self, other: f32) -> f32 {
993-
cfg_match! {
993+
cfg_select! {
994994
// Allow faster implementation that have known good 64-bit float
995995
// implementations. Falling back to the branchy code on targets that don't
996996
// have 64-bit hardware floats or buggy implementations.

library/core/src/slice/sort/select.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! for pivot selection. Using this as a fallback ensures O(n) worst case running time with
77
//! better performance than one would get using heapsort as fallback.
88
9-
use crate::cfg_match;
9+
use crate::cfg_select;
1010
use crate::mem::{self, SizedTypeProperties};
1111
#[cfg(not(feature = "optimize_for_size"))]
1212
use crate::slice::sort::shared::pivot::choose_pivot;
@@ -42,7 +42,7 @@ where
4242
let min_idx = min_index(v, &mut is_less).unwrap();
4343
v.swap(min_idx, index);
4444
} else {
45-
cfg_match! {
45+
cfg_select! {
4646
feature = "optimize_for_size" => {
4747
median_of_medians(v, &mut is_less, index);
4848
}

library/core/src/slice/sort/stable/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::mem::{MaybeUninit, SizedTypeProperties};
77
use crate::slice::sort::shared::smallsort::{
88
SMALL_SORT_GENERAL_SCRATCH_LEN, StableSmallSortTypeImpl, insertion_sort_shift_left,
99
};
10-
use crate::{cfg_match, intrinsics};
10+
use crate::{cfg_select, intrinsics};
1111

1212
pub(crate) mod merge;
1313

@@ -39,13 +39,13 @@ pub fn sort<T, F: FnMut(&T, &T) -> bool, BufT: BufGuard<T>>(v: &mut [T], is_less
3939
return;
4040
}
4141

42-
cfg_match! {
42+
cfg_select! {
4343
any(feature = "optimize_for_size", target_pointer_width = "16") => {
4444
// Unlike driftsort, mergesort only requires len / 2,
4545
// not len - len / 2.
4646
let alloc_len = len / 2;
4747

48-
cfg_match! {
48+
cfg_select! {
4949
target_pointer_width = "16" => {
5050
let mut heap_buf = BufT::with_capacity(alloc_len);
5151
let scratch = heap_buf.as_uninit_slice_mut();

library/core/src/slice/sort/unstable/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::mem::SizedTypeProperties;
55
use crate::slice::sort::shared::find_existing_run;
66
#[cfg(not(any(feature = "optimize_for_size", target_pointer_width = "16")))]
77
use crate::slice::sort::shared::smallsort::insertion_sort_shift_left;
8-
use crate::{cfg_match, intrinsics};
8+
use crate::{cfg_select, intrinsics};
99

1010
pub(crate) mod heapsort;
1111
pub(crate) mod quicksort;
@@ -30,7 +30,7 @@ pub fn sort<T, F: FnMut(&T, &T) -> bool>(v: &mut [T], is_less: &mut F) {
3030
return;
3131
}
3232

33-
cfg_match! {
33+
cfg_select! {
3434
any(feature = "optimize_for_size", target_pointer_width = "16") => {
3535
heapsort::heapsort(v, is_less);
3636
}

library/core/src/slice/sort/unstable/quicksort.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::slice::sort::shared::pivot::choose_pivot;
99
use crate::slice::sort::shared::smallsort::UnstableSmallSortTypeImpl;
1010
#[cfg(not(feature = "optimize_for_size"))]
1111
use crate::slice::sort::unstable::heapsort;
12-
use crate::{cfg_match, intrinsics, ptr};
12+
use crate::{cfg_select, intrinsics, ptr};
1313

1414
/// Sorts `v` recursively.
1515
///
@@ -142,7 +142,7 @@ const fn inst_partition<T, F: FnMut(&T, &T) -> bool>() -> fn(&mut [T], &T, &mut
142142
if size_of::<T>() <= MAX_BRANCHLESS_PARTITION_SIZE {
143143
// Specialize for types that are relatively cheap to copy, where branchless optimizations
144144
// have large leverage e.g. `u64` and `String`.
145-
cfg_match! {
145+
cfg_select! {
146146
feature = "optimize_for_size" => {
147147
partition_lomuto_branchless_simple::<T, F>
148148
}

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
}

0 commit comments

Comments
 (0)