Skip to content

Commit 81b3c9f

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 81b3c9f

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@ edition: 2021
2+
3+
#![feature(macro_metavar_expr)]
4+
5+
#[macro_export]
6+
macro_rules! make_matcher {
7+
($name:ident, $fragment_type:ident) => {
8+
#[macro_export]
9+
macro_rules! $name {
10+
($$_:$fragment_type) => { true };
11+
($$($$_:tt)*) => { false };
12+
}
13+
}
14+
}
15+
16+
make_matcher!(is_expr_from_2021, expr);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 specifiers across edition b
6+
7+
#![feature(expr_fragment_specifier_2024)]
8+
#![feature(macro_metavar_expr)]
9+
#![allow(incomplete_features)]
10+
11+
extern crate metavar_2021;
12+
13+
use metavar_2021::{is_expr_from_2021, make_matcher};
14+
15+
make_matcher!(is_expr_from_2024, expr);
16+
17+
fn main() {
18+
let from_2021 = is_expr_from_2021!(const { 0 });
19+
dbg!(from_2021);
20+
let from_2024 = is_expr_from_2024!(const { 0 });
21+
dbg!(from_2024);
22+
23+
// These capture the current, empirically determined behavior.
24+
//
25+
// It's not clear whether this is the desired behavior, but that's a
26+
// question we can deal with when stabilizing macro_metavar_expr.
27+
assert!(!from_2021);
28+
assert!(!from_2024);
29+
}

0 commit comments

Comments
 (0)