-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
7b18b3e
commit 81b3c9f
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |