Skip to content

Commit

Permalink
Point at match when a parse failure ocurrs inside of it
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 28, 2018
1 parent ea57134 commit d491734
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/libsyntax/parse/parser.rs
Expand Up @@ -2474,7 +2474,11 @@ impl<'a> Parser<'a> {
return Ok(self.mk_expr(lo.to(hi), ex, attrs));
}
if self.eat_keyword(keywords::Match) {
return self.parse_match_expr(attrs);
let match_sp = self.prev_span;
return self.parse_match_expr(attrs).map_err(|mut err| {
err.span_label(match_sp, "while parsing this match expression");
err
});
}
if self.eat_keyword(keywords::Unsafe) {
return self.parse_block_expr(
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/label/label_break_value_illegal_uses.stderr
Expand Up @@ -25,7 +25,9 @@ error: expected one of `.`, `?`, `{`, or an operator, found `'b`
--> $DIR/label_break_value_illegal_uses.rs:28:17
|
LL | match false 'b: {} //~ ERROR expected one of `.`, `?`, `{`, or an operator
| ^^ expected one of `.`, `?`, `{`, or an operator here
| ----- ^^ expected one of `.`, `?`, `{`, or an operator here
| |
| while parsing this match expression

error: aborting due to 4 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/parser/match-refactor-to-expr.rs
Expand Up @@ -12,7 +12,7 @@

fn main() {
let foo =
match
match //~ NOTE while parsing this match expression
Some(4).unwrap_or_else(5)
//~^ NOTE expected one of `.`, `?`, `{`, or an operator here
; //~ NOTE unexpected token
Expand Down
7 changes: 5 additions & 2 deletions src/test/ui/parser/match-refactor-to-expr.stderr
@@ -1,8 +1,11 @@
error: expected one of `.`, `?`, `{`, or an operator, found `;`
--> $DIR/match-refactor-to-expr.rs:18:9
|
LL | match
| ----- help: try removing this `match`
LL | match //~ NOTE while parsing this match expression
| -----
| |
| while parsing this match expression
| help: try removing this `match`
LL | Some(4).unwrap_or_else(5)
| - expected one of `.`, `?`, `{`, or an operator here
LL | //~^ NOTE expected one of `.`, `?`, `{`, or an operator here
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/try-block/try-block-in-match.stderr
Expand Up @@ -2,7 +2,9 @@ error: expected expression, found reserved keyword `try`
--> $DIR/try-block-in-match.rs:16:11
|
LL | match try { false } { _ => {} } //~ ERROR expected expression, found reserved keyword `try`
| ^^^ expected expression
| ----- ^^^ expected expression
| |
| while parsing this match expression

error: aborting due to previous error

0 comments on commit d491734

Please sign in to comment.