diff options
| author | bors <bors@rust-lang.org> | 2020-02-17 11:54:49 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-02-17 11:54:49 +0000 |
| commit | 0176a9eef845e7421b7e2f7ef015333a41a7c027 (patch) | |
| tree | d5320ab0b0e03a6642fcf99e9caa1541463b61b8 /src/librustc_parse/parser | |
| parent | 75b98fbe77d472d85d1691bae5b25e7eefb3609c (diff) | |
| parent | cec2a9fad057f71fc640392ba3fa47602aea12f6 (diff) | |
| download | rust-0176a9eef845e7421b7e2f7ef015333a41a7c027.tar.gz rust-0176a9eef845e7421b7e2f7ef015333a41a7c027.zip | |
Auto merge of #69129 - Centril:macro-legacy-errors, r=petrochenkov
Transition macro_legacy_warnings into a hard error Fixes https://github.com/rust-lang/rust/issues/67098. r? @petrochenkov
Diffstat (limited to 'src/librustc_parse/parser')
| -rw-r--r-- | src/librustc_parse/parser/stmt.rs | 62 |
1 files changed, 9 insertions, 53 deletions
diff --git a/src/librustc_parse/parser/stmt.rs b/src/librustc_parse/parser/stmt.rs index 742fc4802fd..0ce0e0df66a 100644 --- a/src/librustc_parse/parser/stmt.rs +++ b/src/librustc_parse/parser/stmt.rs @@ -22,17 +22,14 @@ impl<'a> Parser<'a> { /// Parses a statement. This stops just before trailing semicolons on everything but items. /// e.g., a `StmtKind::Semi` parses to a `StmtKind::Expr`, leaving the trailing `;` unconsumed. pub fn parse_stmt(&mut self) -> PResult<'a, Option<Stmt>> { - Ok(self.parse_stmt_without_recovery(true).unwrap_or_else(|mut e| { + Ok(self.parse_stmt_without_recovery().unwrap_or_else(|mut e| { e.emit(); self.recover_stmt_(SemiColonMode::Break, BlockMode::Ignore); None })) } - fn parse_stmt_without_recovery( - &mut self, - macro_legacy_warnings: bool, - ) -> PResult<'a, Option<Stmt>> { + fn parse_stmt_without_recovery(&mut self) -> PResult<'a, Option<Stmt>> { maybe_whole!(self, NtStmt, |x| Some(x)); let attrs = self.parse_outer_attributes()?; @@ -64,7 +61,7 @@ impl<'a> Parser<'a> { let path = self.parse_path(PathStyle::Expr)?; if self.eat(&token::Not) { - return self.parse_stmt_mac(lo, attrs.into(), path, macro_legacy_warnings); + return self.parse_stmt_mac(lo, attrs.into(), path); } let expr = if self.check(&token::OpenDelim(token::Brace)) { @@ -127,7 +124,6 @@ impl<'a> Parser<'a> { lo: Span, attrs: AttrVec, path: ast::Path, - legacy_warnings: bool, ) -> PResult<'a, Option<Stmt>> { let args = self.parse_mac_args()?; let delim = args.delim(); @@ -140,30 +136,6 @@ impl<'a> Parser<'a> { let kind = if delim == token::Brace || self.token == token::Semi || self.token == token::Eof { - StmtKind::Mac(P((mac, style, attrs.into()))) - } - // We used to incorrectly stop parsing macro-expanded statements here. - // If the next token will be an error anyway but could have parsed with the - // earlier behavior, stop parsing here and emit a warning to avoid breakage. - else if legacy_warnings - && self.token.can_begin_expr() - && match self.token.kind { - // These can continue an expression, so we can't stop parsing and warn. - token::OpenDelim(token::Paren) - | token::OpenDelim(token::Bracket) - | token::BinOp(token::Minus) - | token::BinOp(token::Star) - | token::BinOp(token::And) - | token::BinOp(token::Or) - | token::AndAnd - | token::OrOr - | token::DotDot - | token::DotDotDot - | token::DotDotEq => false, - _ => true, - } - { - self.warn_missing_semicolon(); StmtKind::Mac(P((mac, style, attrs))) } else { // Since none of the above applied, this is an expression statement macro. @@ -310,7 +282,7 @@ impl<'a> Parser<'a> { // bar; // // which is valid in other languages, but not Rust. - match self.parse_stmt_without_recovery(false) { + match self.parse_stmt_without_recovery() { Ok(Some(stmt)) => { if self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace)) || do_not_suggest_help @@ -369,7 +341,7 @@ impl<'a> Parser<'a> { if self.token == token::Eof { break; } - let stmt = match self.parse_full_stmt(false) { + let stmt = match self.parse_full_stmt() { Err(mut err) => { self.maybe_annotate_with_ascription(&mut err, false); err.emit(); @@ -389,11 +361,11 @@ impl<'a> Parser<'a> { } /// Parses a statement, including the trailing semicolon. - pub fn parse_full_stmt(&mut self, macro_legacy_warnings: bool) -> PResult<'a, Option<Stmt>> { + pub fn parse_full_stmt(&mut self) -> PResult<'a, Option<Stmt>> { // Skip looking for a trailing semicolon when we have an interpolated statement. maybe_whole!(self, NtStmt, |x| Some(x)); - let mut stmt = match self.parse_stmt_without_recovery(macro_legacy_warnings)? { + let mut stmt = match self.parse_stmt_without_recovery()? { Some(stmt) => stmt, None => return Ok(None), }; @@ -433,13 +405,8 @@ impl<'a> Parser<'a> { } } StmtKind::Local(..) => { - // We used to incorrectly allow a macro-expanded let statement to lack a semicolon. - if macro_legacy_warnings && self.token != token::Semi { - self.warn_missing_semicolon(); - } else { - self.expect_semi()?; - eat_semi = false; - } + self.expect_semi()?; + eat_semi = false; } _ => {} } @@ -451,17 +418,6 @@ impl<'a> Parser<'a> { Ok(Some(stmt)) } - fn warn_missing_semicolon(&self) { - self.diagnostic() - .struct_span_warn(self.token.span, { - &format!("expected `;`, found {}", super::token_descr(&self.token)) - }) - .note({ - "this was erroneously allowed and will become a hard error in a future release" - }) - .emit(); - } - pub(super) fn mk_block(&self, stmts: Vec<Stmt>, rules: BlockCheckMode, span: Span) -> P<Block> { P(Block { stmts, id: DUMMY_NODE_ID, rules, span }) } |
