Skip to content

Commit 71415ef

Browse files
committed
Parse excess semicolons as empty stmts for linting
1 parent c01be67 commit 71415ef

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/libsyntax/parse/parser/stmt.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,22 @@ impl<'a> Parser<'a> {
167167
if self.token == token::Semi {
168168
unused_attrs(&attrs, self);
169169
self.bump();
170-
return Ok(None);
170+
let mut last_semi = lo;
171+
while self.token == token::Semi {
172+
last_semi = self.token.span;
173+
self.bump();
174+
}
175+
// We are encoding a string of semicolons as an
176+
// an empty tuple that spans the excess semicolons
177+
// to preserve this info until the lint stage
178+
return Ok(Some(Stmt {
179+
id: ast::DUMMY_NODE_ID,
180+
span: lo.to(last_semi),
181+
node: StmtKind::Semi(self.mk_expr(lo.to(last_semi),
182+
ExprKind::Tup(Vec::new()),
183+
ThinVec::new()
184+
)),
185+
}));
171186
}
172187

173188
if self.token == token::CloseDelim(token::Brace) {

0 commit comments

Comments
 (0)