forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#123865 - eholk:expr_2021, r=fmease
Update `expr` matcher for Edition 2024 and add `expr_2021` nonterminal This commit adds a new nonterminal `expr_2021` in macro patterns, and `expr_fragment_specifier_2024` feature flag. This change also updates `expr` so that on Edition 2024 it will also match `const { ... }` blocks, while `expr_2021` preserves the current behavior of `expr`, matching expressions without `const` blocks. Joint work with `@vincenzopalazzo.` Issue rust-lang#123742
- Loading branch information
Showing
13 changed files
with
204 additions
and
24 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
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
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
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
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
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
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,32 @@ | ||
error: no rules expected the token `const` | ||
--> $DIR/expr_2021_inline_const.rs:21:12 | ||
| | ||
LL | macro_rules! m2021 { | ||
| ------------------ when calling this macro | ||
... | ||
LL | m2021!(const { 1 }); | ||
| ^^^^^ no rules expected this token in macro call | ||
| | ||
note: while trying to match meta-variable `$e:expr_2021` | ||
--> $DIR/expr_2021_inline_const.rs:10:6 | ||
| | ||
LL | ($e:expr_2021) => { | ||
| ^^^^^^^^^^^^ | ||
|
||
error: no rules expected the token `const` | ||
--> $DIR/expr_2021_inline_const.rs:22:12 | ||
| | ||
LL | macro_rules! m2024 { | ||
| ------------------ when calling this macro | ||
... | ||
LL | m2024!(const { 1 }); | ||
| ^^^^^ no rules expected this token in macro call | ||
| | ||
note: while trying to match meta-variable `$e:expr` | ||
--> $DIR/expr_2021_inline_const.rs:16:6 | ||
| | ||
LL | ($e:expr) => { | ||
| ^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
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,17 @@ | ||
error: no rules expected the token `const` | ||
--> $DIR/expr_2021_inline_const.rs:21:12 | ||
| | ||
LL | macro_rules! m2021 { | ||
| ------------------ when calling this macro | ||
... | ||
LL | m2021!(const { 1 }); | ||
| ^^^^^ no rules expected this token in macro call | ||
| | ||
note: while trying to match meta-variable `$e:expr_2021` | ||
--> $DIR/expr_2021_inline_const.rs:10:6 | ||
| | ||
LL | ($e:expr_2021) => { | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
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,23 @@ | ||
//@ revisions: edi2021 edi2024 | ||
//@[edi2024]compile-flags: --edition=2024 -Z unstable-options | ||
//@[edi2021]compile-flags: --edition=2021 | ||
|
||
// This test ensures that the inline const match only on edition 2024 | ||
#![feature(expr_fragment_specifier_2024)] | ||
#![allow(incomplete_features)] | ||
|
||
macro_rules! m2021 { | ||
($e:expr_2021) => { | ||
$e | ||
}; | ||
} | ||
|
||
macro_rules! m2024 { | ||
($e:expr) => { | ||
$e | ||
}; | ||
} | ||
fn main() { | ||
m2021!(const { 1 }); //~ ERROR: no rules expected the token `const` | ||
m2024!(const { 1 }); //[edi2021]~ ERROR: no rules expected the token `const` | ||
} |
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,13 @@ | ||
//@ compile-flags: --edition=2018 | ||
|
||
// This test ensures that expr_2021 is not allowed on pre-2021 editions | ||
|
||
macro_rules! m { | ||
($e:expr_2021) => { //~ ERROR: invalid fragment specifier `expr_2021` | ||
$e | ||
}; | ||
} | ||
|
||
fn main() { | ||
m!(()); //~ ERROR: no rules expected the token `(` | ||
} |
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,26 @@ | ||
error: invalid fragment specifier `expr_2021` | ||
--> $DIR/expr_2021_old_edition.rs:6:6 | ||
| | ||
LL | ($e:expr_2021) => { | ||
| ^^^^^^^^^^^^ | ||
| | ||
= help: fragment specifier `expr_2021` requires Rust 2021 or later | ||
valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis` | ||
|
||
error: no rules expected the token `(` | ||
--> $DIR/expr_2021_old_edition.rs:12:8 | ||
| | ||
LL | macro_rules! m { | ||
| -------------- when calling this macro | ||
... | ||
LL | m!(()); | ||
| ^ no rules expected this token in macro call | ||
| | ||
note: while trying to match meta-variable `$e:ident` | ||
--> $DIR/expr_2021_old_edition.rs:6:6 | ||
| | ||
LL | ($e:expr_2021) => { | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
11 changes: 11 additions & 0 deletions
11
tests/ui/macros/feature-gate-expr_fragment_specifier_2024.rs
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,11 @@ | ||
//@ compile-flags: --edition=2024 -Z unstable-options | ||
|
||
macro_rules! m { | ||
($e:expr_2021) => { //~ ERROR: fragment specifier `expr_2021` is unstable | ||
$e | ||
}; | ||
} | ||
|
||
fn main() { | ||
m!(()); | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/ui/macros/feature-gate-expr_fragment_specifier_2024.stderr
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,13 @@ | ||
error[E0658]: fragment specifier `expr_2021` is unstable | ||
--> $DIR/feature-gate-expr_fragment_specifier_2024.rs:4:6 | ||
| | ||
LL | ($e:expr_2021) => { | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: see issue #123742 <https://github.com/rust-lang/rust/issues/123742> for more information | ||
= help: add `#![feature(expr_fragment_specifier_2024)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |