Skip to content

Commit d63d363

Browse files
committed
Diagnostic tweaks (review)
1 parent 36baa81 commit d63d363

File tree

4 files changed

+15
-22
lines changed

4 files changed

+15
-22
lines changed

src/libsyntax/parse/parser.rs

+11-17
Original file line numberDiff line numberDiff line change
@@ -3231,18 +3231,8 @@ impl<'a> Parser<'a> {
32313231
return Err(err)
32323232
}
32333233
let not_block = self.token != token::OpenDelim(token::Brace);
3234-
let fat_arrow_sp = if self.token == token::FatArrow {
3235-
Some(self.span)
3236-
} else {
3237-
None
3238-
};
32393234
let thn = self.parse_block().map_err(|mut err| {
3240-
if let Some(sp) = fat_arrow_sp {
3241-
// if cond => expr
3242-
err.span_suggestion(sp,
3243-
"only necessary in match arms, not before if blocks",
3244-
"".to_string());
3245-
} else if not_block {
3235+
if not_block {
32463236
err.span_label(lo, "this `if` statement has a condition, but no block");
32473237
}
32483238
err
@@ -3444,7 +3434,7 @@ impl<'a> Parser<'a> {
34443434

34453435
let expr = self.parse_expr_res(Restrictions::STMT_EXPR, None)
34463436
.map_err(|mut err| {
3447-
err.span_label(arrow_span, "while parsing the match arm starting here");
3437+
err.span_label(arrow_span, "while parsing the `match` arm starting here");
34483438
err
34493439
})?;
34503440

@@ -3455,7 +3445,6 @@ impl<'a> Parser<'a> {
34553445
let cm = self.sess.codemap();
34563446
self.expect_one_of(&[token::Comma], &[token::CloseDelim(token::Brace)])
34573447
.map_err(|mut err| {
3458-
err.span_label(arrow_span, "while parsing the match arm starting here");
34593448
match (cm.span_to_lines(expr.span), cm.span_to_lines(arm_start_span)) {
34603449
(Ok(ref expr_lines), Ok(ref arm_start_lines))
34613450
if arm_start_lines.lines[0].end_col == expr_lines.lines[0].end_col
@@ -3472,11 +3461,16 @@ impl<'a> Parser<'a> {
34723461
// | - ^^ self.span
34733462
// | |
34743463
// | parsed until here as `"y" & X`
3475-
err.span_suggestion_short(cm.next_point(arm_start_span),
3476-
"missing a comma here to end this match arm",
3477-
",".to_owned());
3464+
err.span_suggestion_short(
3465+
cm.next_point(arm_start_span),
3466+
"missing a comma here to end this `match` arm",
3467+
",".to_owned()
3468+
);
3469+
}
3470+
_ => {
3471+
err.span_label(arrow_span,
3472+
"while parsing the `match` arm starting here");
34783473
}
3479-
_ => {}
34803474
}
34813475
err
34823476
})?;

src/test/ui/missing-block-hint.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: expected `{`, found `=>`
22
--> $DIR/missing-block-hint.rs:13:18
33
|
44
LL | if (foo) => {} //~ ERROR expected `{`, found `=>`
5-
| ^^ help: only necessary in match arms, not before if blocks
5+
| -- ^^
6+
| |
7+
| this `if` statement has a condition, but no block
68

79
error: expected `{`, found `bar`
810
--> $DIR/missing-block-hint.rs:17:13

src/test/ui/suggestions/missing-comma-in-match.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ fn main() {
1414
&Some(2) => { 3 }
1515
//~^ ERROR expected one of `,`, `.`, `?`, `}`, or an operator, found `=>`
1616
//~| NOTE expected one of `,`, `.`, `?`, `}`, or an operator here
17-
//~^^^^ NOTE while parsing the match arm starting here
1817
_ => 2
1918
};
2019
}

src/test/ui/suggestions/missing-comma-in-match.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error: expected one of `,`, `.`, `?`, `}`, or an operator, found `=>`
22
--> $DIR/missing-comma-in-match.rs:14:18
33
|
44
13 | &None => 1
5-
| -- - help: missing a comma here to end this match arm
6-
| |
7-
| while parsing the match arm starting here
5+
| - help: missing a comma here to end this `match` arm
86
14 | &Some(2) => { 3 }
97
| ^^ expected one of `,`, `.`, `?`, `}`, or an operator here
108

0 commit comments

Comments
 (0)