Skip to content

Commit cec2a9f

Browse files
committed
macro_legacy_warnings -> error
1 parent 2e6eace commit cec2a9f

File tree

7 files changed

+35
-97
lines changed

7 files changed

+35
-97
lines changed

src/librustc_expand/expand.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
821821
span: Span,
822822
) -> AstFragment {
823823
let mut parser = self.cx.new_parser_from_tts(toks);
824-
match parse_ast_fragment(&mut parser, kind, false) {
824+
match parse_ast_fragment(&mut parser, kind) {
825825
Ok(fragment) => {
826826
ensure_complete_parse(&mut parser, path, kind.name(), span);
827827
fragment
@@ -840,7 +840,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
840840
pub fn parse_ast_fragment<'a>(
841841
this: &mut Parser<'a>,
842842
kind: AstFragmentKind,
843-
macro_legacy_warnings: bool,
844843
) -> PResult<'a, AstFragment> {
845844
Ok(match kind {
846845
AstFragmentKind::Items => {
@@ -873,11 +872,9 @@ pub fn parse_ast_fragment<'a>(
873872
}
874873
AstFragmentKind::Stmts => {
875874
let mut stmts = SmallVec::new();
876-
while this.token != token::Eof &&
877-
// won't make progress on a `}`
878-
this.token != token::CloseDelim(token::Brace)
879-
{
880-
if let Some(stmt) = this.parse_full_stmt(macro_legacy_warnings)? {
875+
// Won't make progress on a `}`.
876+
while this.token != token::Eof && this.token != token::CloseDelim(token::Brace) {
877+
if let Some(stmt) = this.parse_full_stmt()? {
881878
stmts.push(stmt);
882879
}
883880
}

src/librustc_expand/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn suggest_slice_pat(e: &mut DiagnosticBuilder<'_>, site_span: Span, parser: &Pa
8787
impl<'a> ParserAnyMacro<'a> {
8888
crate fn make(mut self: Box<ParserAnyMacro<'a>>, kind: AstFragmentKind) -> AstFragment {
8989
let ParserAnyMacro { site_span, macro_ident, ref mut parser, arm_span } = *self;
90-
let fragment = panictry!(parse_ast_fragment(parser, kind, true).map_err(|mut e| {
90+
let fragment = panictry!(parse_ast_fragment(parser, kind).map_err(|mut e| {
9191
if parser.token == token::Eof && e.message().ends_with(", found `<eof>`") {
9292
if !e.span.is_dummy() {
9393
// early end of macro arm (#52866)

src/librustc_parse/parser/stmt.rs

+9-53
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,14 @@ impl<'a> Parser<'a> {
2222
/// Parses a statement. This stops just before trailing semicolons on everything but items.
2323
/// e.g., a `StmtKind::Semi` parses to a `StmtKind::Expr`, leaving the trailing `;` unconsumed.
2424
pub fn parse_stmt(&mut self) -> PResult<'a, Option<Stmt>> {
25-
Ok(self.parse_stmt_without_recovery(true).unwrap_or_else(|mut e| {
25+
Ok(self.parse_stmt_without_recovery().unwrap_or_else(|mut e| {
2626
e.emit();
2727
self.recover_stmt_(SemiColonMode::Break, BlockMode::Ignore);
2828
None
2929
}))
3030
}
3131

32-
fn parse_stmt_without_recovery(
33-
&mut self,
34-
macro_legacy_warnings: bool,
35-
) -> PResult<'a, Option<Stmt>> {
32+
fn parse_stmt_without_recovery(&mut self) -> PResult<'a, Option<Stmt>> {
3633
maybe_whole!(self, NtStmt, |x| Some(x));
3734

3835
let attrs = self.parse_outer_attributes()?;
@@ -74,7 +71,7 @@ impl<'a> Parser<'a> {
7471
let path = self.parse_path(PathStyle::Expr)?;
7572

7673
if self.eat(&token::Not) {
77-
return self.parse_stmt_mac(lo, attrs.into(), path, macro_legacy_warnings);
74+
return self.parse_stmt_mac(lo, attrs.into(), path);
7875
}
7976

8077
let expr = if self.check(&token::OpenDelim(token::Brace)) {
@@ -137,7 +134,6 @@ impl<'a> Parser<'a> {
137134
lo: Span,
138135
attrs: AttrVec,
139136
path: ast::Path,
140-
legacy_warnings: bool,
141137
) -> PResult<'a, Option<Stmt>> {
142138
let args = self.parse_mac_args()?;
143139
let delim = args.delim();
@@ -150,30 +146,6 @@ impl<'a> Parser<'a> {
150146

151147
let kind = if delim == token::Brace || self.token == token::Semi || self.token == token::Eof
152148
{
153-
StmtKind::Mac(P((mac, style, attrs.into())))
154-
}
155-
// We used to incorrectly stop parsing macro-expanded statements here.
156-
// If the next token will be an error anyway but could have parsed with the
157-
// earlier behavior, stop parsing here and emit a warning to avoid breakage.
158-
else if legacy_warnings
159-
&& self.token.can_begin_expr()
160-
&& match self.token.kind {
161-
// These can continue an expression, so we can't stop parsing and warn.
162-
token::OpenDelim(token::Paren)
163-
| token::OpenDelim(token::Bracket)
164-
| token::BinOp(token::Minus)
165-
| token::BinOp(token::Star)
166-
| token::BinOp(token::And)
167-
| token::BinOp(token::Or)
168-
| token::AndAnd
169-
| token::OrOr
170-
| token::DotDot
171-
| token::DotDotDot
172-
| token::DotDotEq => false,
173-
_ => true,
174-
}
175-
{
176-
self.warn_missing_semicolon();
177149
StmtKind::Mac(P((mac, style, attrs)))
178150
} else {
179151
// Since none of the above applied, this is an expression statement macro.
@@ -334,7 +306,7 @@ impl<'a> Parser<'a> {
334306
// bar;
335307
//
336308
// which is valid in other languages, but not Rust.
337-
match self.parse_stmt_without_recovery(false) {
309+
match self.parse_stmt_without_recovery() {
338310
Ok(Some(stmt)) => {
339311
if self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace))
340312
|| do_not_suggest_help
@@ -393,7 +365,7 @@ impl<'a> Parser<'a> {
393365
if self.token == token::Eof {
394366
break;
395367
}
396-
let stmt = match self.parse_full_stmt(false) {
368+
let stmt = match self.parse_full_stmt() {
397369
Err(mut err) => {
398370
self.maybe_annotate_with_ascription(&mut err, false);
399371
err.emit();
@@ -413,11 +385,11 @@ impl<'a> Parser<'a> {
413385
}
414386

415387
/// Parses a statement, including the trailing semicolon.
416-
pub fn parse_full_stmt(&mut self, macro_legacy_warnings: bool) -> PResult<'a, Option<Stmt>> {
388+
pub fn parse_full_stmt(&mut self) -> PResult<'a, Option<Stmt>> {
417389
// Skip looking for a trailing semicolon when we have an interpolated statement.
418390
maybe_whole!(self, NtStmt, |x| Some(x));
419391

420-
let mut stmt = match self.parse_stmt_without_recovery(macro_legacy_warnings)? {
392+
let mut stmt = match self.parse_stmt_without_recovery()? {
421393
Some(stmt) => stmt,
422394
None => return Ok(None),
423395
};
@@ -457,13 +429,8 @@ impl<'a> Parser<'a> {
457429
}
458430
}
459431
StmtKind::Local(..) => {
460-
// We used to incorrectly allow a macro-expanded let statement to lack a semicolon.
461-
if macro_legacy_warnings && self.token != token::Semi {
462-
self.warn_missing_semicolon();
463-
} else {
464-
self.expect_semi()?;
465-
eat_semi = false;
466-
}
432+
self.expect_semi()?;
433+
eat_semi = false;
467434
}
468435
_ => {}
469436
}
@@ -475,17 +442,6 @@ impl<'a> Parser<'a> {
475442
Ok(Some(stmt))
476443
}
477444

478-
fn warn_missing_semicolon(&self) {
479-
self.diagnostic()
480-
.struct_span_warn(self.token.span, {
481-
&format!("expected `;`, found {}", super::token_descr(&self.token))
482-
})
483-
.note({
484-
"this was erroneously allowed and will become a hard error in a future release"
485-
})
486-
.emit();
487-
}
488-
489445
pub(super) fn mk_block(&self, stmts: Vec<Stmt>, rules: BlockCheckMode, span: Span) -> P<Block> {
490446
P(Block { stmts, id: DUMMY_NODE_ID, rules, span })
491447
}

src/test/ui/missing/missing-semicolon-warning.rs

-12
This file was deleted.

src/test/ui/missing/missing-semicolon-warning.stderr

-24
This file was deleted.
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
macro_rules! m {
2+
($($e1:expr),*; $($e2:expr),*) => {
3+
$( let x = $e1 )*; //~ ERROR expected one of `.`, `;`, `?`, or
4+
$( println!("{}", $e2) )*;
5+
}
6+
}
7+
8+
fn main() { m!(0, 0; 0, 0); }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: expected one of `.`, `;`, `?`, or an operator, found keyword `let`
2+
--> $DIR/missing-semicolon.rs:3:12
3+
|
4+
LL | $( let x = $e1 )*;
5+
| ^^^ expected one of `.`, `;`, `?`, or an operator
6+
...
7+
LL | fn main() { m!(0, 0; 0, 0); }
8+
| --------------- in this macro invocation
9+
|
10+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
11+
12+
error: aborting due to previous error
13+

0 commit comments

Comments
 (0)