Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 255586d

Browse files
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. Co-Authored-By: Vincenzo Palazzo <[email protected]> Co-Authored-By: Eric Holk <[email protected]>
1 parent 7b18b3e commit 255586d

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ edition: 2021
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+
}
10+
};
11+
}
12+
make_matcher!(is_expr_from_2021, expr, $);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//@ compile-flags: --edition=2024 -Z unstable-options
2+
//@ aux-build: metavar_2021.rs
3+
//@ run-pass
4+
5+
// This test captures the behavior of macro-generating-macros with fragment
6+
// specifiers across edition boundaries.
7+
8+
#![feature(expr_fragment_specifier_2024)]
9+
#![feature(macro_metavar_expr)]
10+
#![allow(incomplete_features)]
11+
12+
extern crate metavar_2021;
13+
14+
use metavar_2021::{is_expr_from_2021, make_matcher};
15+
16+
make_matcher!(is_expr_from_2024, expr, $);
17+
18+
fn main() {
19+
let from_2021 = is_expr_from_2021!(const { 0 });
20+
dbg!(from_2021);
21+
let from_2024 = is_expr_from_2024!(const { 0 });
22+
dbg!(from_2024);
23+
24+
// These capture the current, empirically determined behavior.
25+
// It's not clear whether this is the desired behavior.
26+
assert!(!from_2021);
27+
assert!(!from_2024);
28+
}

0 commit comments

Comments
 (0)