Skip to content

Commit d491734

Browse files
committed
Point at match when a parse failure ocurrs inside of it
1 parent ea57134 commit d491734

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

src/libsyntax/parse/parser.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,11 @@ impl<'a> Parser<'a> {
24742474
return Ok(self.mk_expr(lo.to(hi), ex, attrs));
24752475
}
24762476
if self.eat_keyword(keywords::Match) {
2477-
return self.parse_match_expr(attrs);
2477+
let match_sp = self.prev_span;
2478+
return self.parse_match_expr(attrs).map_err(|mut err| {
2479+
err.span_label(match_sp, "while parsing this match expression");
2480+
err
2481+
});
24782482
}
24792483
if self.eat_keyword(keywords::Unsafe) {
24802484
return self.parse_block_expr(

src/test/ui/label/label_break_value_illegal_uses.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ error: expected one of `.`, `?`, `{`, or an operator, found `'b`
2525
--> $DIR/label_break_value_illegal_uses.rs:28:17
2626
|
2727
LL | match false 'b: {} //~ ERROR expected one of `.`, `?`, `{`, or an operator
28-
| ^^ expected one of `.`, `?`, `{`, or an operator here
28+
| ----- ^^ expected one of `.`, `?`, `{`, or an operator here
29+
| |
30+
| while parsing this match expression
2931

3032
error: aborting due to 4 previous errors
3133

src/test/ui/parser/match-refactor-to-expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
fn main() {
1414
let foo =
15-
match
15+
match //~ NOTE while parsing this match expression
1616
Some(4).unwrap_or_else(5)
1717
//~^ NOTE expected one of `.`, `?`, `{`, or an operator here
1818
; //~ NOTE unexpected token

src/test/ui/parser/match-refactor-to-expr.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
error: expected one of `.`, `?`, `{`, or an operator, found `;`
22
--> $DIR/match-refactor-to-expr.rs:18:9
33
|
4-
LL | match
5-
| ----- help: try removing this `match`
4+
LL | match //~ NOTE while parsing this match expression
5+
| -----
6+
| |
7+
| while parsing this match expression
8+
| help: try removing this `match`
69
LL | Some(4).unwrap_or_else(5)
710
| - expected one of `.`, `?`, `{`, or an operator here
811
LL | //~^ NOTE expected one of `.`, `?`, `{`, or an operator here

src/test/ui/try-block/try-block-in-match.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: expected expression, found reserved keyword `try`
22
--> $DIR/try-block-in-match.rs:16:11
33
|
44
LL | match try { false } { _ => {} } //~ ERROR expected expression, found reserved keyword `try`
5-
| ^^^ expected expression
5+
| ----- ^^^ expected expression
6+
| |
7+
| while parsing this match expression
68

79
error: aborting due to previous error
810

0 commit comments

Comments
 (0)