Don't ICE for postfix match after as

This commit is contained in:
Michael Goulet 2024-04-02 18:31:42 -04:00
parent 36b6f9b58e
commit 9d116e8e18
3 changed files with 36 additions and 0 deletions

View File

@ -860,6 +860,7 @@ impl<'a> Parser<'a> {
ExprKind::MethodCall(_) => "a method call",
ExprKind::Call(_, _) => "a function call",
ExprKind::Await(_, _) => "`.await`",
ExprKind::Match(_, _, MatchKind::Postfix) => "a postfix match",
ExprKind::Err(_) => return Ok(with_postfix),
_ => unreachable!("parse_dot_or_call_expr_with_ shouldn't produce this"),
}

View File

@ -0,0 +1,7 @@
#![feature(postfix_match)]
fn main() {
1 as i32.match {};
//~^ ERROR cast cannot be followed by a postfix match
//~| ERROR non-exhaustive patterns
}

View File

@ -0,0 +1,28 @@
error: cast cannot be followed by a postfix match
--> $DIR/match-after-as.rs:4:5
|
LL | 1 as i32.match {};
| ^^^^^^^^
|
help: try surrounding the expression in parentheses
|
LL | (1 as i32).match {};
| + +
error[E0004]: non-exhaustive patterns: type `i32` is non-empty
--> $DIR/match-after-as.rs:4:5
|
LL | 1 as i32.match {};
| ^^^^^^^^
|
= note: the matched value is of type `i32`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
|
LL ~ 1 as i32 {
LL + _ => todo!(),
LL ~ };
|
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0004`.