Skip to content

Commit 1bed654

Browse files
committed
1) Addresses #48636
2) Changed position of help message, incase comma is missing 3) added few missing spaces and handled span_suggestion for vscode 4) updated stderr file
1 parent 9af69fe commit 1bed654

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5758,18 +5758,33 @@ impl<'a> Parser<'a> {
57585758
vis: Visibility,
57595759
attrs: Vec<Attribute> )
57605760
-> PResult<'a, StructField> {
5761+
let mut seen_comma: bool = false;
57615762
let a_var = self.parse_name_and_ty(lo, vis, attrs)?;
5763+
if self.token == token::Comma {
5764+
seen_comma = true;
5765+
}
57625766
match self.token {
57635767
token::Comma => {
57645768
self.bump();
57655769
}
57665770
token::CloseDelim(token::Brace) => {}
57675771
token::DocComment(_) => {
5772+
let previous_span = self.prev_span;
57685773
let mut err = self.span_fatal_err(self.span, Error::UselessDocComment);
57695774
self.bump(); // consume the doc comment
5770-
if self.eat(&token::Comma) || self.token == token::CloseDelim(token::Brace) {
5775+
let comma_after_doc_seen = self.eat(&token::Comma);
5776+
// `seen_comma` is always false, because we are inside doc block
5777+
// condition is here to make code more readable
5778+
if seen_comma == false && comma_after_doc_seen == true {
5779+
seen_comma = true;
5780+
}
5781+
if comma_after_doc_seen || self.token == token::CloseDelim(token::Brace) {
57715782
err.emit();
57725783
} else {
5784+
if seen_comma == false {
5785+
let sp = self.sess.codemap().next_point(previous_span);
5786+
err.span_suggestion(sp, "missing comma here", ",".into());
5787+
}
57735788
return Err(err);
57745789
}
57755790
}

src/test/ui/issue-48636.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct S {
12+
x: u8
13+
/// The id of the parent core
14+
y: u8,
15+
}
16+
//~^^^ ERROR found a documentation comment that doesn't document anything
17+
fn main() {}

src/test/ui/issue-48636.stderr

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0585]: found a documentation comment that doesn't document anything
2+
--> $DIR/issue-48636.rs:13:5
3+
|
4+
LL | x: u8
5+
| - help: missing comma here: `,`
6+
LL | /// The id of the parent core
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8+
|
9+
= help: doc comments must come before what they document, maybe a comment was intended with `//`?
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0585`.

0 commit comments

Comments
 (0)