about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLzu Tao <taolzu@gmail.com>2020-07-24 16:24:15 +0000
committerLzu Tao <taolzu@gmail.com>2020-08-08 10:38:49 +0000
commit0a8d4ce055d40bb4897d1cd5c110174ede8ed505 (patch)
tree5ce3a44b1b8e52db0a7e1a9f6884833f190e694d /src
parent57c5da8f1c1d36da3b69e98a75ed54efb4b45329 (diff)
Fallback to pase_expr because match guard accepts struct literals
Diffstat (limited to 'src')
-rw-r--r--src/librustc_parse/parser/expr.rs2
-rw-r--r--src/test/ui/parser/issue-15980.rs7
-rw-r--r--src/test/ui/parser/issue-15980.stderr25
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: 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 previous error
+error: aborting due to 2 previous errors