summary refs log tree commit diff
path: root/src/librustc_parse/parser
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-02-27 04:10:42 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-03-01 23:02:17 +0100
commit176fe3f8ac79e58e35793e6a92c75eed3c8e5b91 (patch)
treefa21c9074e37c5927f3908f71891a37aa6f95021 /src/librustc_parse/parser
parentbeac68a88711a90346ec8b68e3baefbec62b3b0d (diff)
downloadrust-176fe3f8ac79e58e35793e6a92c75eed3c8e5b91.tar.gz
rust-176fe3f8ac79e58e35793e6a92c75eed3c8e5b91.zip
encode `;` stmt w/o expr as `StmtKind::Empty`
Diffstat (limited to 'src/librustc_parse/parser')
-rw-r--r--src/librustc_parse/parser/stmt.rs27
1 files changed, 7 insertions, 20 deletions
diff --git a/src/librustc_parse/parser/stmt.rs b/src/librustc_parse/parser/stmt.rs
index e38a7f2f1c2..3864ec3aaa1 100644
--- a/src/librustc_parse/parser/stmt.rs
+++ b/src/librustc_parse/parser/stmt.rs
@@ -59,23 +59,10 @@ impl<'a> Parser<'a> {
         } else if let Some(item) = self.parse_stmt_item(attrs.clone())? {
             // FIXME: Bad copy of attrs
             self.mk_stmt(lo.to(item.span), StmtKind::Item(P(item)))
-        } else if self.token == token::Semi {
+        } else if self.eat(&token::Semi) {
             // Do not attempt to parse an expression if we're done here.
             self.error_outer_attrs(&attrs);
-            self.bump();
-            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.
-            let kind = StmtKind::Semi(self.mk_expr(
-                lo.to(last_semi),
-                ExprKind::Tup(Vec::new()),
-                AttrVec::new(),
-            ));
-            self.mk_stmt(lo.to(last_semi), kind)
+            self.mk_stmt(lo, StmtKind::Empty)
         } else if self.token != token::CloseDelim(token::Brace) {
             // Remainder are line-expr stmts.
             let e = self.parse_expr_res(Restrictions::STMT_EXPR, Some(attrs.into()))?;
@@ -144,12 +131,11 @@ impl<'a> Parser<'a> {
     /// Error on outer attributes in this context.
     /// Also error if the previous token was a doc comment.
     fn error_outer_attrs(&self, attrs: &[Attribute]) {
-        if !attrs.is_empty() {
-            if matches!(self.prev_token.kind, TokenKind::DocComment(..)) {
-                self.span_fatal_err(self.prev_token.span, Error::UselessDocComment).emit();
+        if let [.., last] = attrs {
+            if last.is_doc_comment() {
+                self.span_fatal_err(last.span, Error::UselessDocComment).emit();
             } else if attrs.iter().any(|a| a.style == AttrStyle::Outer) {
-                self.struct_span_err(self.token.span, "expected statement after outer attribute")
-                    .emit();
+                self.struct_span_err(last.span, "expected statement after outer attribute").emit();
             }
         }
     }
@@ -401,6 +387,7 @@ impl<'a> Parser<'a> {
                 self.expect_semi()?;
                 eat_semi = false;
             }
+            StmtKind::Empty => eat_semi = false,
             _ => {}
         }