Fallback to pase_expr because match guard accepts struct literals

This commit is contained in:
Lzu Tao 2020-07-24 16:24:15 +00:00
parent 57c5da8f1c
commit 0a8d4ce055
3 changed files with 28 additions and 6 deletions

View File

@ -1823,7 +1823,7 @@ impl<'a> Parser<'a> {
let pat = self.parse_top_pat(GateOr::No)?;
let guard = if self.eat_keyword(kw::If) {
let if_span = self.prev_token.span;
let cond = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?;
let cond = self.parse_expr()?;
if let ExprKind::Let(..) = cond.kind {
// Remove the last feature gating of a `let` expression since it's stable.
self.sess.gated_spans.ungate_last(sym::let_chains, cond.span);

View File

@ -4,9 +4,14 @@ fn main(){
let x: io::Result<()> = Ok(());
match x {
Err(ref e) if e.kind == io::EndOfFile {
//~^ ERROR expected one of `!`, `.`, `::`, `=>`, `?`, or an operator, found `{`
//~^ NOTE while parsing this struct
return
//~^ ERROR expected identifier, found keyword `return`
//~| NOTE expected identifier, found keyword
}
//~^ NOTE expected one of `.`, `=>`, `?`, or an operator
_ => {}
//~^ ERROR expected one of `.`, `=>`, `?`, or an operator, found reserved identifier `_`
//~| NOTE unexpected token
}
}

View File

@ -1,8 +1,25 @@
error: expected one of `!`, `.`, `::`, `=>`, `?`, or an operator, found `{`
--> $DIR/issue-15980.rs:6:47
error: expected identifier, found keyword `return`
--> $DIR/issue-15980.rs:8:13
|
LL | Err(ref e) if e.kind == io::EndOfFile {
| ^ expected one of `!`, `.`, `::`, `=>`, `?`, or an operator
| ------------- while parsing this struct
LL |
LL | return
| ^^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
|
LL | r#return
|
error: aborting due to previous error
error: expected one of `.`, `=>`, `?`, or an operator, found reserved identifier `_`
--> $DIR/issue-15980.rs:13:9
|
LL | }
| - expected one of `.`, `=>`, `?`, or an operator
LL |
LL | _ => {}
| ^ unexpected token
error: aborting due to 2 previous errors