Skip to content

Commit 66bd8ee

Browse files
committed
Fix ICE when parsing token trees after an error.
1 parent 031c116 commit 66bd8ee

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

src/libsyntax/parse/parser.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,10 @@ impl<'a> Parser<'a> {
802802
let mut first: bool = true;
803803
let mut v = vec![];
804804
while !kets.contains(&&self.token) {
805+
match self.token {
806+
token::CloseDelim(..) | token::Eof => break,
807+
_ => {}
808+
};
805809
match sep.sep {
806810
Some(ref t) => {
807811
if first {
@@ -2608,9 +2612,12 @@ impl<'a> Parser<'a> {
26082612
return Ok((None, kleene_op));
26092613
}
26102614

2611-
let separator = self.bump_and_get();
2615+
let separator = match self.token {
2616+
token::CloseDelim(..) => None,
2617+
_ => Some(self.bump_and_get()),
2618+
};
26122619
match parse_kleene_op(self)? {
2613-
Some(zerok) => Ok((Some(separator), zerok)),
2620+
Some(zerok) => Ok((separator, zerok)),
26142621
None => return Err(self.fatal("expected `*` or `+`"))
26152622
}
26162623
}
@@ -2647,7 +2654,7 @@ impl<'a> Parser<'a> {
26472654
tts: tts,
26482655
})))
26492656
},
2650-
token::CloseDelim(_) | token::Eof => unreachable!(),
2657+
token::CloseDelim(..) | token::Eof => Ok(TokenTree::Token(self.span, token::Eof)),
26512658
token::Dollar | token::SubstNt(..) if self.quote_depth > 0 => self.parse_unquoted(),
26522659
_ => Ok(TokenTree::Token(self.span, self.bump_and_get())),
26532660
}

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

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
macro_rules! assign {
12+
(($($a:tt)*) = ($($b:tt))*) => { //~ ERROR expected `*` or `+`
13+
$($a)* = $($b)*
14+
}
15+
}
16+
17+
fn main() {}

src/test/compile-fail/issue-39616.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 foo(a: [0; 1]) {} //~ ERROR expected type, found `0`
12+
//~| ERROR expected one of `->`, `where`, or `{`, found `]`
13+
// FIXME(jseyfried): avoid emitting the second error (preexisting)
14+
15+
fn main() {}

0 commit comments

Comments
 (0)