diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2019-10-20 14:35:46 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2019-10-28 10:53:13 -0700 |
| commit | d673d0ac8462bd30612b0cce719ac0bf15dfaf86 (patch) | |
| tree | 0822ed1a284b2761a7b2a61b33a5b5dcaf0a123d /src/libsyntax/parse/parser/stmt.rs | |
| parent | 03a50ae9b87021d4a166c70d2c932f1cb0aa8f28 (diff) | |
| download | rust-d673d0ac8462bd30612b0cce719ac0bf15dfaf86.tar.gz rust-d673d0ac8462bd30612b0cce719ac0bf15dfaf86.zip | |
Use heuristics to recover parsing of missing `;`
- Detect `,` and `:` typos where `;` was intended. - When the next token could have been the start of a new statement, detect a missing semicolon.
Diffstat (limited to 'src/libsyntax/parse/parser/stmt.rs')
| -rw-r--r-- | src/libsyntax/parse/parser/stmt.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser/stmt.rs b/src/libsyntax/parse/parser/stmt.rs index ea7e4c05ea1..4f51fefe66f 100644 --- a/src/libsyntax/parse/parser/stmt.rs +++ b/src/libsyntax/parse/parser/stmt.rs @@ -432,6 +432,7 @@ impl<'a> Parser<'a> { None => return Ok(None), }; + let mut eat_semi = true; match stmt.kind { StmtKind::Expr(ref expr) if self.token != token::Eof => { // expression without semicolon @@ -453,13 +454,14 @@ impl<'a> Parser<'a> { if macro_legacy_warnings && self.token != token::Semi { self.warn_missing_semicolon(); } else { - self.expect_one_of(&[], &[token::Semi])?; + self.expect_semi()?; + eat_semi = false; } } _ => {} } - if self.eat(&token::Semi) { + if eat_semi && self.eat(&token::Semi) { stmt = stmt.add_trailing_semicolon(); } stmt.span = stmt.span.to(self.prev_span); |
