-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update expr
matcher for Edition 2024 and add expr_2021
nonterminal
#123865
Changes from all commits
ef6478b
65da4ad
73303c3
a55d063
f364011
3986ea0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
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 | ||
|
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` | ||
} |
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 `(` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
error: invalid fragment specifier `expr_2021` | ||
eholk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--> $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` | ||
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would probably split this into two separate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think that'd be better. Let me poke around at it some more, I'm still getting the hang of the diagnostics system. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I'd rather save this for another PR so we can wrap this one up. I feel like otherwise I'll sit on this for another week or two, and I'd like to get this in as a foundation for similar edition-related changes. |
||
|
||
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 | ||
|
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!(()); | ||
} |
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a performance expert, so I might be wrong here, but I think the only thing that could cause a performance issue is the token.span.edition().
If we follow the call stack, the edition() will resolve in the following call: https://github.com/rust-lang/rust/blob/master/compiler/rustc_span/src/hygiene.rs#L877-L879.
If we repeat this call for every expression token, we could see a performance decrease.