]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_parse/parser/stmt.rs
Auto merge of #69576 - matthiaskrgr:nightly_bootstrap_from_beta, r=Centril
[rust.git] / src / librustc_parse / parser / stmt.rs
index d3852690c9d80caa7f469fc7532d467f9a77a125..3864ec3aaa163be822f4e007d3a07a0025536870 100644 (file)
@@ -6,15 +6,15 @@
 use crate::maybe_whole;
 use crate::DirectoryOwnership;
 
+use rustc_ast::ast;
+use rustc_ast::ast::{AttrStyle, AttrVec, Attribute, Mac, MacStmtStyle};
+use rustc_ast::ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt, StmtKind, DUMMY_NODE_ID};
+use rustc_ast::ptr::P;
+use rustc_ast::token::{self, TokenKind};
+use rustc_ast::util::classify;
 use rustc_errors::{Applicability, PResult};
 use rustc_span::source_map::{BytePos, Span};
 use rustc_span::symbol::{kw, sym};
-use syntax::ast;
-use syntax::ast::{AttrStyle, AttrVec, Attribute, Mac, MacStmtStyle};
-use syntax::ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt, StmtKind, DUMMY_NODE_ID};
-use syntax::ptr::P;
-use syntax::token::{self, TokenKind};
-use syntax::util::classify;
 
 use std::mem;
 
@@ -59,23 +59,10 @@ fn parse_stmt_without_recovery(&mut self) -> PResult<'a, Option<Stmt>> {
         } 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 @@ fn parse_stmt_mac(&mut self, lo: Span, attrs: AttrVec, path: ast::Path) -> PResu
     /// 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 @@ pub fn parse_full_stmt(&mut self) -> PResult<'a, Option<Stmt>> {
                 self.expect_semi()?;
                 eat_semi = false;
             }
+            StmtKind::Empty => eat_semi = false,
             _ => {}
         }