Skip to content

Commit

Permalink
Rollup merge of rust-lang#39674 - jseyfried:fix_token_tree_parsing_IC…
Browse files Browse the repository at this point in the history
…E, r=nrc

parser: fix ICE when parsing token trees after an error

Fixes rust-lang#39388, fixes rust-lang#39616.
r? @nrc
  • Loading branch information
frewsxcv authored Feb 10, 2017
2 parents 41653fd + 66bd8ee commit ed7f3c4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 `+`"))
}
}
Expand Down Expand Up @@ -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())),
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/compile-fail/issue-39388.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions src/test/compile-fail/issue-39616.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit ed7f3c4

Please sign in to comment.