5 files changed +123
-0
lines changed Original file line number Diff line number Diff line change
1
+ //@ edition: 2021
2
+
3
+ #[ macro_export]
4
+ macro_rules! make_macro_with_input {
5
+ ( $i: ident) => {
6
+ macro_rules! macro_inner_input {
7
+ ( ) => {
8
+ pub fn $i( ) { }
9
+ } ;
10
+ }
11
+ } ;
12
+ }
13
+
14
+ #[ macro_export]
15
+ macro_rules! make_macro {
16
+ ( ) => {
17
+ macro_rules! macro_inner {
18
+ ( ) => {
19
+ pub fn gen ( ) { }
20
+ } ;
21
+ }
22
+ } ;
23
+ }
Original file line number Diff line number Diff line change
1
+ //@ edition: 2024
2
+
3
+ #[ macro_export]
4
+ macro_rules! make_macro_with_input {
5
+ ( $i: ident) => {
6
+ macro_rules! macro_inner_input {
7
+ ( ) => {
8
+ pub fn $i( ) { }
9
+ } ;
10
+ }
11
+ } ;
12
+ }
13
+
14
+ #[ macro_export]
15
+ macro_rules! make_macro {
16
+ ( ) => {
17
+ macro_rules! macro_inner {
18
+ ( ) => {
19
+ pub fn gen ( ) { }
20
+ } ;
21
+ }
22
+ } ;
23
+ }
Original file line number Diff line number Diff line change
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
+ //@ aux-crate: nested_macro_rules_dep_2024=nested_macro_rules_dep_2024.rs
15
+ //@ edition:2024
16
+
17
+ mod with_input {
18
+ // If we change the macro_rules input behavior, then this should pass
19
+ // because `gen` is written in a context with 2021 behavior.
20
+ nested_macro_rules_dep_2024:: make_macro_with_input!{ gen }
21
+ macro_inner_input ! { }
22
+ //~^ ERROR found reserved keyword
23
+ }
24
+ mod no_input {
25
+ nested_macro_rules_dep_2024:: make_macro!{ }
26
+ macro_inner ! { }
27
+ //~^ ERROR found reserved keyword
28
+ }
29
+
30
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: expected identifier, found reserved keyword `gen`
2
+ --> $DIR/nested-macro-rules-edition-local-2021.rs:21:5
3
+ |
4
+ LL | macro_inner_input!{}
5
+ | ^^^^^^^^^^^^^^^^^^^^ expected identifier, found reserved keyword
6
+ |
7
+ = note: this error originates in the macro `macro_inner_input` (in Nightly builds, run with -Z macro-backtrace for more info)
8
+ help: escape `gen` to use it as an identifier
9
+ |
10
+ LL | nested_macro_rules_dep_2024::make_macro_with_input!{r#gen}
11
+ | ++
12
+
13
+ error: expected identifier, found reserved keyword `gen`
14
+ --> $DIR/nested-macro-rules-edition-local-2021.rs:26:5
15
+ |
16
+ LL | macro_inner!{}
17
+ | ^^^^^^^^^^^^^^ expected identifier, found reserved keyword
18
+ |
19
+ = note: this error originates in the macro `macro_inner` (in Nightly builds, run with -Z macro-backtrace for more info)
20
+ help: escape `gen` to use it as an identifier
21
+ --> $DIR/auxiliary/nested_macro_rules_dep_2024.rs:19:24
22
+ |
23
+ LL | pub fn r#gen() {}
24
+ | ++
25
+
26
+ error: aborting due to 2 previous errors
27
+
Original file line number Diff line number Diff line change
1
+ // See nested-macro-rules-edition-local-2021.rs for a description of this test.
2
+ //
3
+ // This flips the editions to show the opposite behavior.
4
+
5
+ //@ aux-crate: nested_macro_rules_dep_2021=nested_macro_rules_dep_2021.rs
6
+ //@ edition:2024
7
+ //@ check-pass
8
+
9
+ mod with_input {
10
+ // If we change the macro_rules input behavior, then this should fail
11
+ // because `gen` is written in a context with 2024 behavior.
12
+ nested_macro_rules_dep_2021:: make_macro_with_input!{ gen }
13
+ macro_inner_input ! { }
14
+ }
15
+ mod no_input {
16
+ nested_macro_rules_dep_2021:: make_macro!{ }
17
+ macro_inner ! { }
18
+ }
19
+
20
+ fn main ( ) { }
0 commit comments