Skip to content

Doc comments present after a particular syntax error cause an unhelpful error message to be output. #48946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5758,18 +5758,33 @@ impl<'a> Parser<'a> {
vis: Visibility,
attrs: Vec<Attribute> )
-> PResult<'a, StructField> {
let mut seen_comma: bool = false;
let a_var = self.parse_name_and_ty(lo, vis, attrs)?;
if self.token == token::Comma {
seen_comma = true;
}
match self.token {
token::Comma => {
self.bump();
}
token::CloseDelim(token::Brace) => {}
token::DocComment(_) => {
let previous_span = self.prev_span;
let mut err = self.span_fatal_err(self.span, Error::UselessDocComment);
self.bump(); // consume the doc comment
if self.eat(&token::Comma) || self.token == token::CloseDelim(token::Brace) {
let comma_after_doc_seen = self.eat(&token::Comma);
// `seen_comma` is always false, because we are inside doc block
// condition is here to make code more readable
if seen_comma == false && comma_after_doc_seen == true {
seen_comma = true;
}
if comma_after_doc_seen || self.token == token::CloseDelim(token::Brace) {
err.emit();
} else {
if seen_comma == false {
let sp = self.sess.codemap().next_point(previous_span);
err.span_suggestion(sp, "missing comma here", ",".into());
}
return Err(err);
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/issue-48636.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2018 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

struct S {
x: u8
/// The id of the parent core
y: u8,
}
//~^^^ ERROR found a documentation comment that doesn't document anything
fn main() {}
13 changes: 13 additions & 0 deletions src/test/ui/issue-48636.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0585]: found a documentation comment that doesn't document anything
--> $DIR/issue-48636.rs:13:5
|
LL | x: u8
| - help: missing comma here: `,`
LL | /// The id of the parent core
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: doc comments must come before what they document, maybe a comment was intended with `//`?

error: aborting due to previous error

For more information about this error, try `rustc --explain E0585`.