Use expr parse restrictions for let expr parsing

This commit is contained in:
Michael Goulet 2022-08-01 01:13:16 +00:00
parent 7cdd937bb8
commit 6be7a87f9c
6 changed files with 365 additions and 306 deletions

View file

@ -32,6 +32,8 @@ fn _if_let_guard() {
() if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
//~^ ERROR `if let` guards are experimental
//~| ERROR expected expression, found `let` statement
//~| ERROR expected expression, found `let` statement
//~| ERROR expected expression, found `let` statement
() if let Range { start: _, end: _ } = (true..true) && false => {}
//~^ ERROR `if let` guards are experimental

View file

@ -41,19 +41,31 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:52:16
--> $DIR/feature-gate.rs:32:55
|
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:32:68
|
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:54:16
|
LL | use_expr!((let 0 = 1 && 0 == 0));
| ^^^
error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:54:16
--> $DIR/feature-gate.rs:56:16
|
LL | use_expr!((let 0 = 1));
| ^^^
error: no rules expected the token `let`
--> $DIR/feature-gate.rs:62:15
--> $DIR/feature-gate.rs:64:15
|
LL | macro_rules! use_expr {
| --------------------- when calling this macro
@ -102,7 +114,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
= help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`
error[E0658]: `if let` guards are experimental
--> $DIR/feature-gate.rs:36:12
--> $DIR/feature-gate.rs:38:12
|
LL | () if let Range { start: _, end: _ } = (true..true) && false => {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -112,7 +124,7 @@ LL | () if let Range { start: _, end: _ } = (true..true) && false => {}
= help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`
error[E0658]: `if let` guards are experimental
--> $DIR/feature-gate.rs:58:12
--> $DIR/feature-gate.rs:60:12
|
LL | () if let 0 = 1 => {}
| ^^^^^^^^^^^^
@ -121,6 +133,6 @@ LL | () if let 0 = 1 => {}
= help: add `#![feature(if_let_guard)]` to the crate attributes to enable
= help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`
error: aborting due to 16 previous errors
error: aborting due to 18 previous errors
For more information about this error, try `rustc --explain E0658`.

View file

@ -51,6 +51,8 @@ fn _if() {
//~| ERROR `let` expressions are not supported here
//~| ERROR `let` expressions are not supported here
//~| ERROR expected expression, found `let` statement
//~| ERROR expected expression, found `let` statement
//~| ERROR expected expression, found `let` statement
}
fn _while() {
@ -81,6 +83,8 @@ fn _while() {
//~| ERROR `let` expressions are not supported here
//~| ERROR `let` expressions are not supported here
//~| ERROR expected expression, found `let` statement
//~| ERROR expected expression, found `let` statement
//~| ERROR expected expression, found `let` statement
}
fn _macros() {
@ -146,6 +150,7 @@ fn nested_within_if_expr() {
//~| ERROR expected expression, found `let` statement
if true || (true && let 0 = 0) {}
//~^ ERROR `let` expressions are not supported here
//~| ERROR expected expression, found `let` statement
let mut x = true;
if x = let 0 = 0 {}
@ -237,6 +242,7 @@ fn nested_within_while_expr() {
//~| ERROR expected expression, found `let` statement
while true || (true && let 0 = 0) {}
//~^ ERROR `let` expressions are not supported here
//~| ERROR expected expression, found `let` statement
let mut x = true;
while x = let 0 = 0 {}
@ -388,16 +394,19 @@ fn inside_const_generic_arguments() {
if let A::<{
true && let 1 = 1
//~^ ERROR `let` expressions are not supported here
//~| ERROR expected expression, found `let` statement
}>::O = 5 {}
while let A::<{
true && let 1 = 1
//~^ ERROR `let` expressions are not supported here
//~| ERROR expected expression, found `let` statement
}>::O = 5 {}
if A::<{
true && let 1 = 1
//~^ ERROR `let` expressions are not supported here
//~| ERROR expected expression, found `let` statement
}>::O == 5 {}
// In the cases above we have `ExprKind::Block` to help us out.
@ -409,7 +418,8 @@ fn inside_const_generic_arguments() {
if A::<
true && let 1 = 1
//~^ ERROR `let` expressions are not supported here
//~| ERROR expressions must be enclosed in braces
//~| ERROR expressions must be enclosed in braces
//~| ERROR expected expression, found `let` statement
>::O == 5 {}
}