]> git.lizzy.rs Git - rust.git/commitdiff
Parse excess semicolons as empty stmts for linting
authornathanwhit <nathan.whitaker01@gmail.com>
Thu, 25 Jul 2019 15:51:05 +0000 (11:51 -0400)
committernathanwhit <nathan.whitaker01@gmail.com>
Mon, 12 Aug 2019 14:14:07 +0000 (10:14 -0400)
src/libsyntax/parse/parser/stmt.rs

index f182edcbff4372e40cad2383f943db1bd7bf75b1..750d8fbbddc001e7f5421ec3a281efa9aeb77d29 100644 (file)
@@ -167,7 +167,22 @@ fn parse_stmt_without_recovery(
                     if self.token == token::Semi {
                         unused_attrs(&attrs, self);
                         self.bump();
-                        return Ok(None);
+                        let mut last_semi = lo;
+                        while self.token == token::Semi {
+                            last_semi = self.token.span;
+                            self.bump();
+                        }
+                        // We are encoding a string of semicolons as an
+                        // an empty tuple that spans the excess semicolons
+                        // to preserve this info until the lint stage
+                        return Ok(Some(Stmt {
+                            id: ast::DUMMY_NODE_ID,
+                            span: lo.to(last_semi),
+                            node: StmtKind::Semi(self.mk_expr(lo.to(last_semi),
+                                ExprKind::Tup(Vec::new()),
+                                ThinVec::new()
+                            )),
+                        }));
                     }
 
                     if self.token == token::CloseDelim(token::Brace) {