|
| 1 | +// This checks the behavior of how nested macro_rules definitions are handled |
| 2 | +// with regards to edition spans. Prior to https://github.com/rust-lang/rust/pull/133274, |
| 3 | +// the compiler would compile the inner macro with the edition of the local crate. |
| 4 | +// Afterwards, it uses the edition where the macro was *defined*. |
| 5 | +// |
| 6 | +// Unfortunately macro_rules compiler discards the edition of any *input* that |
| 7 | +// was used to generate the macro. This is possibly not the behavior that we |
| 8 | +// want. If we want to keep with the philosophy that code should follow the |
| 9 | +// edition rules of the crate where it is written, then presumably we would |
| 10 | +// want the input tokens to retain the edition of where they were written. |
| 11 | +// |
| 12 | +// See https://github.com/rust-lang/rust/issues/135669 for more. |
| 13 | +// |
| 14 | +// This has two revisions, one where local=2021 and the dep=2024. The other |
| 15 | +// revision is vice-versa. |
| 16 | + |
| 17 | +//@ revisions: e2021 e2024 |
| 18 | +//@[e2021] edition:2021 |
| 19 | +//@[e2024] edition:2024 |
| 20 | +//@[e2021] aux-crate: nested_macro_rules_dep=nested_macro_rules_dep_2024.rs |
| 21 | +//@[e2024] aux-crate: nested_macro_rules_dep=nested_macro_rules_dep_2021.rs |
| 22 | +//@[e2024] check-pass |
| 23 | + |
| 24 | +mod with_input { |
| 25 | + // If we change the macro_rules input behavior, then this should pass when |
| 26 | + // local edition is 2021 because `gen` is written in a context with 2021 |
| 27 | + // behavior. For local edition 2024, the reverse would be true and this |
| 28 | + // should fail. |
| 29 | + nested_macro_rules_dep::make_macro_with_input!{gen} |
| 30 | + macro_inner_input!{} |
| 31 | + //[e2021]~^ ERROR found reserved keyword |
| 32 | +} |
| 33 | +mod no_input { |
| 34 | + nested_macro_rules_dep::make_macro!{} |
| 35 | + macro_inner!{} |
| 36 | + //[e2021]~^ ERROR found reserved keyword |
| 37 | +} |
| 38 | + |
| 39 | +fn main() {} |
0 commit comments