diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6653e6672183..69b272344984 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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 @@ -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 })?; @@ -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 @@ -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 })?; diff --git a/src/test/ui/missing-block-hint.stderr b/src/test/ui/missing-block-hint.stderr index ae583d0d4ba4..a48eff890b33 100644 --- a/src/test/ui/missing-block-hint.stderr +++ b/src/test/ui/missing-block-hint.stderr @@ -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 diff --git a/src/test/ui/suggestions/missing-comma-in-match.rs b/src/test/ui/suggestions/missing-comma-in-match.rs index e02a8df3343b..6f86cdea3cf5 100644 --- a/src/test/ui/suggestions/missing-comma-in-match.rs +++ b/src/test/ui/suggestions/missing-comma-in-match.rs @@ -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 }; } diff --git a/src/test/ui/suggestions/missing-comma-in-match.stderr b/src/test/ui/suggestions/missing-comma-in-match.stderr index 864fde49a5e5..71123a160a5f 100644 --- a/src/test/ui/suggestions/missing-comma-in-match.stderr +++ b/src/test/ui/suggestions/missing-comma-in-match.stderr @@ -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