From 66bd8eede5e79423a7046fa936ab8557c4e323f1 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Wed, 8 Feb 2017 23:38:41 +0000 Subject: [PATCH] Fix ICE when parsing token trees after an error. --- src/libsyntax/parse/parser.rs | 13 ++++++++++--- src/test/compile-fail/issue-39388.rs | 17 +++++++++++++++++ src/test/compile-fail/issue-39616.rs | 15 +++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/test/compile-fail/issue-39388.rs create mode 100644 src/test/compile-fail/issue-39616.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 45d8354d317d..b051928ff9d3 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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())), } diff --git a/src/test/compile-fail/issue-39388.rs b/src/test/compile-fail/issue-39388.rs new file mode 100644 index 000000000000..6994d2199d27 --- /dev/null +++ b/src/test/compile-fail/issue-39388.rs @@ -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 or the MIT license +// , 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() {} diff --git a/src/test/compile-fail/issue-39616.rs b/src/test/compile-fail/issue-39616.rs new file mode 100644 index 000000000000..d601249c036b --- /dev/null +++ b/src/test/compile-fail/issue-39616.rs @@ -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 or the MIT license +// , 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() {}