Consume trailing doc comments to avoid parse errors

This commit is contained in:
Esteban Küber 2017-11-24 07:34:24 -08:00
parent 0e93b75d27
commit f103342b8f
3 changed files with 13 additions and 6 deletions

View File

@ -5422,9 +5422,8 @@ impl<'a> Parser<'a> {
token::CloseDelim(token::Brace) => {}
token::DocComment(_) => {
let mut err = self.span_fatal_err(self.span, Error::UselessDocComment);
if self.eat(&token::Comma) ||
self.look_ahead(1, |t| *t == token::CloseDelim(token::Brace))
{
self.bump(); // consume the doc comment
if self.eat(&token::Comma) || self.token == token::CloseDelim(token::Brace) {
err.emit();
} else {
return Err(err);

View File

@ -9,12 +9,20 @@
// except according to those terms.
// compile-flags: -Z continue-parse-after-error
struct X {
a: u8 /** document a */,
//~^ ERROR found a documentation comment that doesn't document anything
//~| HELP maybe a comment was intended
}
fn main() {
let y = X {a: 1};
struct Y {
a: u8 /// document a
//~^ ERROR found a documentation comment that doesn't document anything
//~| HELP maybe a comment was intended
}
fn main() {
let x = X { a: 1 };
let y = Y { a: 1 };
}

View File

@ -11,7 +11,7 @@
macro_rules! failed {
() => {{
let x = 5 ""; //~ ERROR found `""`
}} //~ ERROR macro expansion ignores token `}`
}}
}
fn main() {