Skip to content

Commit

Permalink
Rollup merge of rust-lang#129755 - vincenzopalazzo:macros/recursive-m…
Browse files Browse the repository at this point in the history
…acros-between-edition, r=compiler-errors

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.

See the original suggestion rust-lang#123865 (comment)

Tracking:

- rust-lang#123742
  • Loading branch information
workingjubilee authored Sep 19, 2024
2 parents a5cf8bb + dd6460b commit fa0d0da
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/ui/macros/auxiliary/metavar_2018.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ edition: 2018
#[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 };
(A | B) => { false };
}
};
}
make_matcher!(is_expr_from_2018, expr, $);
make_matcher!(is_pat_from_2018, pat, $);
38 changes: 38 additions & 0 deletions tests/ui/macros/metavar_cross_edition_recursive_macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//@ compile-flags: --edition=2024 -Z unstable-options
//@ aux-build: metavar_2018.rs
//@ known-bug: #130484
//@ 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_2018;

use metavar_2018::{is_expr_from_2018, is_pat_from_2018, make_matcher};

make_matcher!(is_expr_from_2024, expr, $);
make_matcher!(is_pat_from_2024, pat, $);

fn main() {
// Check expr
let from_2018 = is_expr_from_2018!(const { 0 });
dbg!(from_2018);
let from_2024 = is_expr_from_2024!(const { 0 });
dbg!(from_2024);

assert!(!from_2018);
assert!(!from_2024); // from_2024 will be true once #130484 is fixed

// Check pat
let from_2018 = is_pat_from_2018!(A | B);
dbg!(from_2018);
let from_2024 = is_pat_from_2024!(A | B);
dbg!(from_2024);

assert!(!from_2018);
assert!(!from_2024); // from_2024 will be true once #130484 is fixed
}

0 comments on commit fa0d0da

Please sign in to comment.