diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-09-20 15:45:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-20 15:45:45 +0200 |
| commit | 9cbb1cb07cb19da265e8be9b0d31f6c9107ae2c3 (patch) | |
| tree | 162f2f79125ac343ec4b7f83cf20f8378d7572f5 | |
| parent | 5c60185c538088a964a1f675710812d49fb27153 (diff) | |
| parent | dd6460ba9f6c325211c6b2d819fe0653dc94a1ba (diff) | |
| download | rust-9cbb1cb07cb19da265e8be9b0d31f6c9107ae2c3.tar.gz rust-9cbb1cb07cb19da265e8be9b0d31f6c9107ae2c3.zip | |
Rollup merge of #129755 - vincenzopalazzo:macros/recursive-macros-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 https://github.com/rust-lang/rust/pull/123865#discussion_r1577176199 Tracking: - https://github.com/rust-lang/rust/issues/123742
| -rw-r--r-- | tests/ui/macros/auxiliary/metavar_2018.rs | 14 | ||||
| -rw-r--r-- | tests/ui/macros/metavar_cross_edition_recursive_macros.rs | 38 |
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/ui/macros/auxiliary/metavar_2018.rs b/tests/ui/macros/auxiliary/metavar_2018.rs new file mode 100644 index 00000000000..7e8523a9edf --- /dev/null +++ b/tests/ui/macros/auxiliary/metavar_2018.rs @@ -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, $); diff --git a/tests/ui/macros/metavar_cross_edition_recursive_macros.rs b/tests/ui/macros/metavar_cross_edition_recursive_macros.rs new file mode 100644 index 00000000000..3eec1208b89 --- /dev/null +++ b/tests/ui/macros/metavar_cross_edition_recursive_macros.rs @@ -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 +} |
