Skip to content

Commit

Permalink
test: cross-edition metavar fragment specifiers
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vincenzopalazzo and eholk committed Sep 8, 2024
1 parent 7b18b3e commit 81b3c9f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/ui/macros/auxiliary/metavar_2021.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ edition: 2021

#![feature(macro_metavar_expr)]

#[macro_export]
macro_rules! make_matcher {
($name:ident, $fragment_type:ident) => {
#[macro_export]
macro_rules! $name {
($$_:$fragment_type) => { true };
($$($$_:tt)*) => { false };
}
}
}

make_matcher!(is_expr_from_2021, expr);
29 changes: 29 additions & 0 deletions tests/ui/macros/expr_2021_with_metavar_expr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//@ 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 b

#![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, but that's a
// question we can deal with when stabilizing macro_metavar_expr.
assert!(!from_2021);
assert!(!from_2024);
}

0 comments on commit 81b3c9f

Please sign in to comment.