From 0a8d4ce055d40bb4897d1cd5c110174ede8ed505 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 24 Jul 2020 16:24:15 +0000 Subject: [PATCH] Fallback to pase_expr because match guard accepts struct literals --- src/librustc_parse/parser/expr.rs | 2 +- src/test/ui/parser/issue-15980.rs | 7 ++++++- src/test/ui/parser/issue-15980.stderr | 25 +++++++++++++++++++++---- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index 564b017aab8..6f03aea798c 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -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); diff --git a/src/test/ui/parser/issue-15980.rs b/src/test/ui/parser/issue-15980.rs index 5392f87388c..87faa7d5ff1 100644 --- a/src/test/ui/parser/issue-15980.rs +++ b/src/test/ui/parser/issue-15980.rs @@ -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 } } diff --git a/src/test/ui/parser/issue-15980.stderr b/src/test/ui/parser/issue-15980.stderr index 3f6f015fd27..5cefead2c74 100644 --- a/src/test/ui/parser/issue-15980.stderr +++ b/src/test/ui/parser/issue-15980.stderr @@ -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