Skip to content

Commit f103342

Browse files
committed
Consume trailing doc comments to avoid parse errors
1 parent 0e93b75 commit f103342

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/libsyntax/parse/parser.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5422,9 +5422,8 @@ impl<'a> Parser<'a> {
54225422
token::CloseDelim(token::Brace) => {}
54235423
token::DocComment(_) => {
54245424
let mut err = self.span_fatal_err(self.span, Error::UselessDocComment);
5425-
if self.eat(&token::Comma) ||
5426-
self.look_ahead(1, |t| *t == token::CloseDelim(token::Brace))
5427-
{
5425+
self.bump(); // consume the doc comment
5426+
if self.eat(&token::Comma) || self.token == token::CloseDelim(token::Brace) {
54285427
err.emit();
54295428
} else {
54305429
return Err(err);

src/test/parse-fail/doc-after-struct-field.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@
99
// except according to those terms.
1010

1111
// compile-flags: -Z continue-parse-after-error
12+
1213
struct X {
1314
a: u8 /** document a */,
1415
//~^ ERROR found a documentation comment that doesn't document anything
1516
//~| HELP maybe a comment was intended
1617
}
1718

19+
struct Y {
20+
a: u8 /// document a
21+
//~^ ERROR found a documentation comment that doesn't document anything
22+
//~| HELP maybe a comment was intended
23+
}
24+
1825
fn main() {
19-
let y = X {a: 1};
26+
let x = X { a: 1 };
27+
let y = Y { a: 1 };
2028
}

src/test/parse-fail/issue-37234.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
macro_rules! failed {
1212
() => {{
1313
let x = 5 ""; //~ ERROR found `""`
14-
}} //~ ERROR macro expansion ignores token `}`
14+
}}
1515
}
1616

1717
fn main() {

0 commit comments

Comments
 (0)