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:
parent
7b18b3eb6d
commit
255586d659
12
tests/ui/macros/auxiliary/metavar_2021.rs
Normal file
12
tests/ui/macros/auxiliary/metavar_2021.rs
Normal 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, $);
|
28
tests/ui/macros/expr_2021_with_metavar_expr.rs
Normal file
28
tests/ui/macros/expr_2021_with_metavar_expr.rs
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user