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 <vincenzopalazzodev@gmail.com>
Co-Authored-By: Eric Holk <eric@theincredibleholk.org>
This commit is contained in:
Vincenzo Palazzo 2024-08-29 18:52:44 +00:00 committed by Eric Holk
parent 7b18b3eb6d
commit 255586d659
No known key found for this signature in database
GPG Key ID: 8EA6B43ED4CE0911
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,12 @@
//@ edition: 2021
#[macro_export]
macro_rules! make_matcher {
($name:ident, $fragment_type:ident, $d:tt) => {
#[macro_export]
macro_rules! $name {
($d _:$fragment_type) => { true };
(const { 0 }) => { false };
}
};
}
make_matcher!(is_expr_from_2021, expr, $);

View File

@ -0,0 +1,28 @@
//@ compile-flags: --edition=2024 -Z unstable-options
//@ aux-build: metavar_2021.rs
//@ run-pass
// This test captures the behavior of macro-generating-macros with fragment
// specifiers across edition boundaries.
#![feature(expr_fragment_specifier_2024)]
#![feature(macro_metavar_expr)]
#![allow(incomplete_features)]
extern crate metavar_2021;
use metavar_2021::{is_expr_from_2021, make_matcher};
make_matcher!(is_expr_from_2024, expr, $);
fn main() {
let from_2021 = is_expr_from_2021!(const { 0 });
dbg!(from_2021);
let from_2024 = is_expr_from_2024!(const { 0 });
dbg!(from_2024);
// These capture the current, empirically determined behavior.
// It's not clear whether this is the desired behavior.
assert!(!from_2021);
assert!(!from_2024);
}