Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c20a58d

Browse filesBrowse files
authored
Rollup merge of #136509 - ehuss:nested-macro-rules-edition, r=jieyouxu
Add tests for nested macro_rules edition behavior This adds tests to check the behavior of how nested macro_rules definitions work across edition boundaries. This covers a change in behavior due to #133274. See #135669
2 parents ba42006 + 4636dd9 commit c20a58d
Copy full SHA for c20a58d

File tree

Expand file treeCollapse file tree

4 files changed

+112
-0
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+112
-0
lines changed
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error: expected identifier, found reserved keyword `gen`
2+
--> $DIR/nested-macro-rules-edition.rs:30: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::make_macro_with_input!{r#gen}
11+
| ++
12+
13+
error: expected identifier, found reserved keyword `gen`
14+
--> $DIR/nested-macro-rules-edition.rs:35: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+
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.