Skip to content

Commit bf4bd43

Browse files
authored
Unrolled build for rust-lang#130313
Rollup merge of rust-lang#130313 - c410-f3r:unlock-rfc-2011, r=thomcc [`cfg_match`] Generalize inputs cc rust-lang#115585 Changes the input type from `item` to `tt`, which makes the macro have the same functionality of `cfg_if`. Also adds a test to ensure that `stmt_expr_attributes` is not triggered.
2 parents 58420a0 + ae15032 commit bf4bd43

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

library/core/src/macros/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ pub macro assert_matches {
229229
pub macro cfg_match {
230230
// with a final wildcard
231231
(
232-
$(cfg($initial_meta:meta) => { $($initial_tokens:item)* })+
233-
_ => { $($extra_tokens:item)* }
232+
$(cfg($initial_meta:meta) => { $($initial_tokens:tt)* })+
233+
_ => { $($extra_tokens:tt)* }
234234
) => {
235235
cfg_match! {
236236
@__items ();
@@ -241,7 +241,7 @@ pub macro cfg_match {
241241

242242
// without a final wildcard
243243
(
244-
$(cfg($extra_meta:meta) => { $($extra_tokens:item)* })*
244+
$(cfg($extra_meta:meta) => { $($extra_tokens:tt)* })*
245245
) => {
246246
cfg_match! {
247247
@__items ();
@@ -256,7 +256,7 @@ pub macro cfg_match {
256256
(@__items ($($_:meta,)*);) => {},
257257
(
258258
@__items ($($no:meta,)*);
259-
(($($yes:meta)?) ($($tokens:item)*)),
259+
(($($yes:meta)?) ($($tokens:tt)*)),
260260
$($rest:tt,)*
261261
) => {
262262
// Emit all items within one block, applying an appropriate #[cfg]. The
@@ -279,7 +279,7 @@ pub macro cfg_match {
279279

280280
// Internal macro to make __apply work out right for different match types,
281281
// because of how macros match/expand stuff.
282-
(@__identity $($tokens:item)*) => {
282+
(@__identity $($tokens:tt)*) => {
283283
$($tokens)*
284284
}
285285
}

library/core/tests/macros.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(unused_must_use)]
2+
13
#[allow(dead_code)]
24
trait Trait {
35
fn blah(&self);
@@ -173,3 +175,21 @@ fn cfg_match_two_functions() {
173175
bar2();
174176
}
175177
}
178+
179+
fn _accepts_expressions() -> i32 {
180+
cfg_match! {
181+
cfg(unix) => { 1 }
182+
_ => { 2 }
183+
}
184+
}
185+
186+
// The current implementation expands to a macro call, which allows the use of expression
187+
// statements.
188+
fn _allows_stmt_expr_attributes() {
189+
let one = 1;
190+
let two = 2;
191+
cfg_match! {
192+
cfg(unix) => { one * two; }
193+
_ => { one + two; }
194+
}
195+
}

0 commit comments

Comments
 (0)