Skip to content

Commit eed86fa

Browse files
committed
Don't spin expanding stmt macros.
If we can't make progress when parsing a macro expansion as a statement then we should just bail. This alleviates the symptoms shown in e.g. #37113 but it doesn't fix the problem that parsing invalid enum bodies (and others) leaves the parser in a crappy state.
1 parent a5b6a9f commit eed86fa

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/libsyntax/ext/expand.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,9 @@ impl<'a> Parser<'a> {
536536
}
537537
ExpansionKind::Stmts => {
538538
let mut stmts = SmallVector::zero();
539-
while self.token != token::Eof {
539+
while self.token != token::Eof &&
540+
// won't make progress on a `}`
541+
self.token != token::CloseDelim(token::Brace) {
540542
if let Some(stmt) = self.parse_full_stmt(macro_legacy_warnings)? {
541543
stmts.push(stmt);
542544
}

src/test/parse-fail/issue-37234.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
macro_rules! failed {
12+
() => {{
13+
let x = 5 ""; //~ ERROR found `""`
14+
}} //~ ERROR macro expansion ignores token `}`
15+
}
16+
17+
fn main() {
18+
failed!();
19+
}

0 commit comments

Comments
 (0)