diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 45d8354d317dc..b051928ff9d3c 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 0000000000000..6994d2199d276 --- /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 0000000000000..d601249c036b1 --- /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() {}