forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This makes it possible to use `inline_const` (rust-lang#76001) and `let_chains` (rust-lang#53667) inside macros' `expr` patterns in a future edition by bifurcating the `expr` nonterminal in a similar way to `pat2021` to remove some backwards compatibility exceptions that disallow `const`/`let` at the beginning of an `expr` match. Fixes rust-lang#84155 and relaxes the backward compat restriction from rust-lang#80135 for a future edition. This is not intended to go into 2021 as it I don't think it's simple to write an automatic fix, and certainly not now that it's past the soft deadline for inclusion in 2021 by a long shot. Here is a pathological case of rust-lang#79908 that forces this to be an edition change: ```rust macro_rules! evil { ($e:expr) => { // or something else const {$e-1} }; (const $b:block) => { const {$b} } } fn main() { let x = 5; match x { evil!(const { 5 }) => panic!("oh no"), _ => (), }; } ```
- Loading branch information
Showing
9 changed files
with
111 additions
and
17 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,8 @@ | ||
// feature gate test for edition_macro_expr | ||
|
||
macro_rules! mac { | ||
($x:expr2015) => {}; //~ERROR `expr2015` and `expr202x` are unstable | ||
($x:expr202x) => {}; //~ERROR `expr2015` and `expr202x` are unstable | ||
} | ||
|
||
fn main() {} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/feature-gates/feature-gate-edition_macro_expr.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,19 @@ | ||
error[E0658]: `expr2015` and `expr202x` are unstable. | ||
--> $DIR/feature-gate-edition_macro_expr.rs:4:9 | ||
| | ||
LL | ($x:expr2015) => {}; | ||
| ^^^^^^^^ | ||
| | ||
= help: add `#![feature(edition_macro_expr)]` to the crate attributes to enable | ||
|
||
error[E0658]: `expr2015` and `expr202x` are unstable. | ||
--> $DIR/feature-gate-edition_macro_expr.rs:5:9 | ||
| | ||
LL | ($x:expr202x) => {}; | ||
| ^^^^^^^^ | ||
| | ||
= help: add `#![feature(edition_macro_expr)]` to the crate attributes to enable | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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,34 @@ | ||
// run-pass | ||
|
||
#![feature(edition_macro_expr)] | ||
#![feature(inline_const)] | ||
#![allow(incomplete_features)] | ||
|
||
macro_rules! new_const { | ||
($e:expr202x) => { | ||
$e | ||
}; | ||
(const $e:block) => { | ||
1 | ||
}; | ||
} | ||
|
||
macro_rules! old_const { | ||
($e:expr2015) => { | ||
$e | ||
}; | ||
(const $e:block) => { | ||
1 | ||
}; | ||
} | ||
|
||
fn main() { | ||
match 1 { | ||
old_const!(const { 2 }) => (), | ||
_ => unreachable!(), | ||
} | ||
match 1 { | ||
new_const!(const { 2 }) => unreachable!(), | ||
_ => (), | ||
} | ||
} |