diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-07 11:00:40 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-10 08:35:23 +0100 |
| commit | 09997e72272157a88c40cd2b1b1b7a14f808c0e0 (patch) | |
| tree | 18b34f8c291b2ffa76f74181f645c412040c90b9 /src/librustc_parse | |
| parent | c01b3e6996a803d7794546cbcbba867eff8fb6e2 (diff) | |
| download | rust-09997e72272157a88c40cd2b1b1b7a14f808c0e0.tar.gz rust-09997e72272157a88c40cd2b1b1b7a14f808c0e0.zip | |
error_block_no_opening_brace: handle closures better
Diffstat (limited to 'src/librustc_parse')
| -rw-r--r-- | src/librustc_parse/parser/stmt.rs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/librustc_parse/parser/stmt.rs b/src/librustc_parse/parser/stmt.rs index 8afc86c704d..fb85f54b136 100644 --- a/src/librustc_parse/parser/stmt.rs +++ b/src/librustc_parse/parser/stmt.rs @@ -259,16 +259,14 @@ impl<'a> Parser<'a> { // // which is valid in other languages, but not Rust. match self.parse_stmt_without_recovery() { - Ok(Some(stmt)) => { + // If the next token is an open brace (e.g., `if a b {`), the place- + // inside-a-block suggestion would be more likely wrong than right. + Ok(Some(_)) if self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace)) - || do_not_suggest_help - { - // If the next token is an open brace (e.g., `if a b {`), the place- - // inside-a-block suggestion would be more likely wrong than right. - e.span_label(sp, "expected `{`"); - return Err(e); - } - let stmt_span = if self.eat(&token::Semi) { + || do_not_suggest_help => {} + Ok(Some(stmt)) => { + let stmt_own_line = self.sess.source_map().is_line_before_span_empty(sp); + let stmt_span = if stmt_own_line && self.eat(&token::Semi) { // Expand the span to include the semicolon. stmt.span.with_hi(self.prev_token.span.hi()) } else { |
