Skip to content

Commit

Permalink
Diagnostic tweaks (review)
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Feb 27, 2018
1 parent 36baa81 commit d63d363
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
28 changes: 11 additions & 17 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3231,18 +3231,8 @@ impl<'a> Parser<'a> {
return Err(err)
}
let not_block = self.token != token::OpenDelim(token::Brace);
let fat_arrow_sp = if self.token == token::FatArrow {
Some(self.span)
} else {
None
};
let thn = self.parse_block().map_err(|mut err| {
if let Some(sp) = fat_arrow_sp {
// if cond => expr
err.span_suggestion(sp,
"only necessary in match arms, not before if blocks",
"".to_string());
} else if not_block {
if not_block {
err.span_label(lo, "this `if` statement has a condition, but no block");
}
err
Expand Down Expand Up @@ -3444,7 +3434,7 @@ impl<'a> Parser<'a> {

let expr = self.parse_expr_res(Restrictions::STMT_EXPR, None)
.map_err(|mut err| {
err.span_label(arrow_span, "while parsing the match arm starting here");
err.span_label(arrow_span, "while parsing the `match` arm starting here");
err
})?;

Expand All @@ -3455,7 +3445,6 @@ impl<'a> Parser<'a> {
let cm = self.sess.codemap();
self.expect_one_of(&[token::Comma], &[token::CloseDelim(token::Brace)])
.map_err(|mut err| {
err.span_label(arrow_span, "while parsing the match arm starting here");
match (cm.span_to_lines(expr.span), cm.span_to_lines(arm_start_span)) {
(Ok(ref expr_lines), Ok(ref arm_start_lines))
if arm_start_lines.lines[0].end_col == expr_lines.lines[0].end_col
Expand All @@ -3472,11 +3461,16 @@ impl<'a> Parser<'a> {
// | - ^^ self.span
// | |
// | parsed until here as `"y" & X`
err.span_suggestion_short(cm.next_point(arm_start_span),
"missing a comma here to end this match arm",
",".to_owned());
err.span_suggestion_short(
cm.next_point(arm_start_span),
"missing a comma here to end this `match` arm",
",".to_owned()
);
}
_ => {
err.span_label(arrow_span,
"while parsing the `match` arm starting here");
}
_ => {}
}
err
})?;
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/missing-block-hint.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error: expected `{`, found `=>`
--> $DIR/missing-block-hint.rs:13:18
|
LL | if (foo) => {} //~ ERROR expected `{`, found `=>`
| ^^ help: only necessary in match arms, not before if blocks
| -- ^^
| |
| this `if` statement has a condition, but no block

error: expected `{`, found `bar`
--> $DIR/missing-block-hint.rs:17:13
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/suggestions/missing-comma-in-match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ fn main() {
&Some(2) => { 3 }
//~^ ERROR expected one of `,`, `.`, `?`, `}`, or an operator, found `=>`
//~| NOTE expected one of `,`, `.`, `?`, `}`, or an operator here
//~^^^^ NOTE while parsing the match arm starting here
_ => 2
};
}
4 changes: 1 addition & 3 deletions src/test/ui/suggestions/missing-comma-in-match.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ error: expected one of `,`, `.`, `?`, `}`, or an operator, found `=>`
--> $DIR/missing-comma-in-match.rs:14:18
|
13 | &None => 1
| -- - help: missing a comma here to end this match arm
| |
| while parsing the match arm starting here
| - help: missing a comma here to end this `match` arm
14 | &Some(2) => { 3 }
| ^^ expected one of `,`, `.`, `?`, `}`, or an operator here

Expand Down

0 comments on commit d63d363

Please sign in to comment.