Skip to content

Commit 0a8d4ce

Browse files
committed
Fallback to pase_expr because match guard accepts struct literals
1 parent 57c5da8 commit 0a8d4ce

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

src/librustc_parse/parser/expr.rs

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

src/test/ui/parser/issue-15980.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ fn main(){
44
let x: io::Result<()> = Ok(());
55
match x {
66
Err(ref e) if e.kind == io::EndOfFile {
7-
//~^ ERROR expected one of `!`, `.`, `::`, `=>`, `?`, or an operator, found `{`
7+
//~^ NOTE while parsing this struct
88
return
9+
//~^ ERROR expected identifier, found keyword `return`
10+
//~| NOTE expected identifier, found keyword
911
}
12+
//~^ NOTE expected one of `.`, `=>`, `?`, or an operator
1013
_ => {}
14+
//~^ ERROR expected one of `.`, `=>`, `?`, or an operator, found reserved identifier `_`
15+
//~| NOTE unexpected token
1116
}
1217
}

src/test/ui/parser/issue-15980.stderr

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1-
error: expected one of `!`, `.`, `::`, `=>`, `?`, or an operator, found `{`
2-
--> $DIR/issue-15980.rs:6:47
1+
error: expected identifier, found keyword `return`
2+
--> $DIR/issue-15980.rs:8:13
33
|
44
LL | Err(ref e) if e.kind == io::EndOfFile {
5-
| ^ expected one of `!`, `.`, `::`, `=>`, `?`, or an operator
5+
| ------------- while parsing this struct
6+
LL |
7+
LL | return
8+
| ^^^^^^ expected identifier, found keyword
9+
|
10+
help: you can escape reserved keywords to use them as identifiers
11+
|
12+
LL | r#return
13+
|
14+
15+
error: expected one of `.`, `=>`, `?`, or an operator, found reserved identifier `_`
16+
--> $DIR/issue-15980.rs:13:9
17+
|
18+
LL | }
19+
| - expected one of `.`, `=>`, `?`, or an operator
20+
LL |
21+
LL | _ => {}
22+
| ^ unexpected token
623

7-
error: aborting due to previous error
24+
error: aborting due to 2 previous errors
825

0 commit comments

Comments
 (0)