Skip to content

Commit 6ab0c0b

Browse files
authored
Rollup merge of rust-lang#39730 - jseyfried:fix_empty_seq_rep_ice, r=nrc
macros: fix ICE on certain sequence repetitions Fixes rust-lang#39709. r? @nrc
2 parents 3f3ff76 + b3d7399 commit 6ab0c0b

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

Diff for: src/libsyntax/parse/parser.rs

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

Diff for: src/test/compile-fail/issue-39709.rs

+15
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)