Fix ICE when parsing token trees after an error.
This commit is contained in:
parent
031c1168b9
commit
66bd8eede5
3 changed files with 42 additions and 3 deletions
|
@ -802,6 +802,10 @@ impl<'a> Parser<'a> {
|
|||
let mut first: bool = true;
|
||||
let mut v = vec![];
|
||||
while !kets.contains(&&self.token) {
|
||||
match self.token {
|
||||
token::CloseDelim(..) | token::Eof => break,
|
||||
_ => {}
|
||||
};
|
||||
match sep.sep {
|
||||
Some(ref t) => {
|
||||
if first {
|
||||
|
@ -2608,9 +2612,12 @@ impl<'a> Parser<'a> {
|
|||
return Ok((None, kleene_op));
|
||||
}
|
||||
|
||||
let separator = self.bump_and_get();
|
||||
let separator = match self.token {
|
||||
token::CloseDelim(..) => None,
|
||||
_ => Some(self.bump_and_get()),
|
||||
};
|
||||
match parse_kleene_op(self)? {
|
||||
Some(zerok) => Ok((Some(separator), zerok)),
|
||||
Some(zerok) => Ok((separator, zerok)),
|
||||
None => return Err(self.fatal("expected `*` or `+`"))
|
||||
}
|
||||
}
|
||||
|
@ -2647,7 +2654,7 @@ impl<'a> Parser<'a> {
|
|||
tts: tts,
|
||||
})))
|
||||
},
|
||||
token::CloseDelim(_) | token::Eof => unreachable!(),
|
||||
token::CloseDelim(..) | token::Eof => Ok(TokenTree::Token(self.span, token::Eof)),
|
||||
token::Dollar | token::SubstNt(..) if self.quote_depth > 0 => self.parse_unquoted(),
|
||||
_ => Ok(TokenTree::Token(self.span, self.bump_and_get())),
|
||||
}
|
||||
|
|
17
src/test/compile-fail/issue-39388.rs
Normal file
17
src/test/compile-fail/issue-39388.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
macro_rules! assign {
|
||||
(($($a:tt)*) = ($($b:tt))*) => { //~ ERROR expected `*` or `+`
|
||||
$($a)* = $($b)*
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
15
src/test/compile-fail/issue-39616.rs
Normal file
15
src/test/compile-fail/issue-39616.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn foo(a: [0; 1]) {} //~ ERROR expected type, found `0`
|
||||
//~| ERROR expected one of `->`, `where`, or `{`, found `]`
|
||||
// FIXME(jseyfried): avoid emitting the second error (preexisting)
|
||||
|
||||
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue