From 255586d6598c0033b50cb0165bf11e10ef125878 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Thu, 29 Aug 2024 18:52:44 +0000 Subject: [PATCH] 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 Co-Authored-By: Eric Holk --- tests/ui/macros/auxiliary/metavar_2021.rs | 12 ++++++++ .../ui/macros/expr_2021_with_metavar_expr.rs | 28 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/ui/macros/auxiliary/metavar_2021.rs create mode 100644 tests/ui/macros/expr_2021_with_metavar_expr.rs diff --git a/tests/ui/macros/auxiliary/metavar_2021.rs b/tests/ui/macros/auxiliary/metavar_2021.rs new file mode 100644 index 00000000000..de5350c6164 --- /dev/null +++ b/tests/ui/macros/auxiliary/metavar_2021.rs @@ -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, $); diff --git a/tests/ui/macros/expr_2021_with_metavar_expr.rs b/tests/ui/macros/expr_2021_with_metavar_expr.rs new file mode 100644 index 00000000000..a3da68cc8db --- /dev/null +++ b/tests/ui/macros/expr_2021_with_metavar_expr.rs @@ -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); +}