Skip to content

Commit 6e7cdf1

Browse files
jseyfriedbrson
authored andcommitted
Fix ICE on certain sequence repetitions.
1 parent 8b08e61 commit 6e7cdf1

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,20 @@ impl<'a> Parser<'a> {
304304
if i + 1 < tts.len() {
305305
self.tts.push((tts, i + 1));
306306
}
307-
if let TokenTree::Token(sp, tok) = tt {
308-
TokenAndSpan { tok: tok, sp: sp }
309-
} else {
310-
self.tts.push((tt, 0));
311-
continue
307+
// FIXME(jseyfried): remove after fixing #39390 in #39419.
308+
if self.quote_depth > 0 {
309+
if let TokenTree::Sequence(sp, _) = tt {
310+
self.span_err(sp, "attempted to repeat an expression containing no \
311+
syntax variables matched as repeating at this depth");
312+
}
313+
}
314+
match tt {
315+
TokenTree::Token(sp, tok) => TokenAndSpan { tok: tok, sp: sp },
316+
_ if tt.len() > 0 => {
317+
self.tts.push((tt, 0));
318+
continue
319+
}
320+
_ => continue,
312321
}
313322
} else {
314323
TokenAndSpan { tok: token::Eof, sp: self.span }

src/test/compile-fail/issue-39709.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 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+
fn main() {
12+
println!("{}", { macro_rules! x { ($()*) => {} } 33 });
13+
//~^ ERROR no syntax variables matched as repeating at this depth
14+
}
15+

0 commit comments

Comments
 (0)