Skip to content

Commit

Permalink
Consume trailing doc comments to avoid parse errors
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Nov 24, 2017
1 parent 0e93b75 commit f103342
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion src/test/parse-fail/doc-after-struct-field.rs
Expand Up @@ -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
}

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 y = X {a: 1};
let x = X { a: 1 };
let y = Y { a: 1 };
}
2 changes: 1 addition & 1 deletion src/test/parse-fail/issue-37234.rs
Expand Up @@ -11,7 +11,7 @@
macro_rules! failed {
() => {{
let x = 5 ""; //~ ERROR found `""`
}} //~ ERROR macro expansion ignores token `}`
}}
}

fn main() {
Expand Down

0 comments on commit f103342

Please sign in to comment.