Skip to content

Commit 68e715c

Browse files
jseyfriedbrson
authored andcommitted
Fix ICE when parsing token trees after an error.
1 parent 6e7cdf1 commit 68e715c

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,10 @@ impl<'a> Parser<'a> {
813813
let mut first: bool = true;
814814
let mut v = vec![];
815815
while !kets.contains(&&self.token) {
816+
match self.token {
817+
token::CloseDelim(..) | token::Eof => break,
818+
_ => {}
819+
};
816820
match sep.sep {
817821
Some(ref t) => {
818822
if first {
@@ -2606,9 +2610,12 @@ impl<'a> Parser<'a> {
26062610
return Ok((None, kleene_op));
26072611
}
26082612

2609-
let separator = self.bump_and_get();
2613+
let separator = match self.token {
2614+
token::CloseDelim(..) => None,
2615+
_ => Some(self.bump_and_get()),
2616+
};
26102617
match parse_kleene_op(self)? {
2611-
Some(zerok) => Ok((Some(separator), zerok)),
2618+
Some(zerok) => Ok((separator, zerok)),
26122619
None => return Err(self.fatal("expected `*` or `+`"))
26132620
}
26142621
}
@@ -2645,7 +2652,7 @@ impl<'a> Parser<'a> {
26452652
tts: tts,
26462653
})))
26472654
},
2648-
token::CloseDelim(_) | token::Eof => unreachable!(),
2655+
token::CloseDelim(..) | token::Eof => Ok(TokenTree::Token(self.span, token::Eof)),
26492656
token::Dollar | token::SubstNt(..) if self.quote_depth > 0 => self.parse_unquoted(),
26502657
_ => Ok(TokenTree::Token(self.span, self.bump_and_get())),
26512658
}

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

Lines changed: 17 additions & 0 deletions
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

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