Skip to content

Commit 2a897cf

Browse files
authored
Unrolled build for rust-lang#129755
Rollup merge of rust-lang#129755 - vincenzopalazzo:macros/recursive-macros-between-edition, r=compiler-errors test: cross-edition metavar fragment specifiers There's a subtle interaction between macros with metavar expressions and the edition-dependent fragment matching behavior. This test illustrates the current behavior when using macro-generating-macros across crate boundaries with different editions. See the original suggestion rust-lang#123865 (comment) Tracking: - rust-lang#123742
2 parents 1a5a224 + dd6460b commit 2a897cf

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ edition: 2018
2+
#[macro_export]
3+
macro_rules! make_matcher {
4+
($name:ident, $fragment_type:ident, $d:tt) => {
5+
#[macro_export]
6+
macro_rules! $name {
7+
($d _:$fragment_type) => { true };
8+
(const { 0 }) => { false };
9+
(A | B) => { false };
10+
}
11+
};
12+
}
13+
make_matcher!(is_expr_from_2018, expr, $);
14+
make_matcher!(is_pat_from_2018, pat, $);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//@ compile-flags: --edition=2024 -Z unstable-options
2+
//@ aux-build: metavar_2018.rs
3+
//@ known-bug: #130484
4+
//@ run-pass
5+
6+
// This test captures the behavior of macro-generating-macros with fragment
7+
// specifiers across edition boundaries.
8+
9+
#![feature(expr_fragment_specifier_2024)]
10+
#![feature(macro_metavar_expr)]
11+
#![allow(incomplete_features)]
12+
13+
extern crate metavar_2018;
14+
15+
use metavar_2018::{is_expr_from_2018, is_pat_from_2018, make_matcher};
16+
17+
make_matcher!(is_expr_from_2024, expr, $);
18+
make_matcher!(is_pat_from_2024, pat, $);
19+
20+
fn main() {
21+
// Check expr
22+
let from_2018 = is_expr_from_2018!(const { 0 });
23+
dbg!(from_2018);
24+
let from_2024 = is_expr_from_2024!(const { 0 });
25+
dbg!(from_2024);
26+
27+
assert!(!from_2018);
28+
assert!(!from_2024); // from_2024 will be true once #130484 is fixed
29+
30+
// Check pat
31+
let from_2018 = is_pat_from_2018!(A | B);
32+
dbg!(from_2018);
33+
let from_2024 = is_pat_from_2024!(A | B);
34+
dbg!(from_2024);
35+
36+
assert!(!from_2018);
37+
assert!(!from_2024); // from_2024 will be true once #130484 is fixed
38+
}

0 commit comments

Comments
 (0)