Skip to content

Commit 4da129d

Browse files
authored
Auto merge of #37246 - goffrie:no-loop, r=jseyfried
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 and #37234 but it doesn't fix the problem that parsing invalid enum bodies (and others) leaves the parser in a crappy state. I'm not sold on this strategy (checking `tokens_consumed`), so if anyone has a better idea, I'm all ears!
2 parents 280362a + eed86fa commit 4da129d

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
@@ -533,7 +533,9 @@ impl<'a> Parser<'a> {
533533
}
534534
ExpansionKind::Stmts => {
535535
let mut stmts = SmallVector::zero();
536-
while self.token != token::Eof {
536+
while self.token != token::Eof &&
537+
// won't make progress on a `}`
538+
self.token != token::CloseDelim(token::Brace) {
537539
if let Some(stmt) = self.parse_full_stmt(macro_legacy_warnings)? {
538540
stmts.push(stmt);
539541
}

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)