diff options
author | Pramod Bisht <pramodpsb@outlook.com> | 2018-04-21 18:39:34 +0530 |
---|---|---|
committer | Pramod Bisht <pramodpsb@outlook.com> | 2018-04-22 11:43:25 +0530 |
commit | 1bed654053c9abb0c48cf6d17c8f77c4acec4bc9 (patch) | |
tree | 57325bc796014f0623887c5abf1732158e36943a | |
parent | 9af69fe2320bde44b96d85d316a95083fb65c4b8 (diff) | |
download | rust-1bed654053c9abb0c48cf6d17c8f77c4acec4bc9.tar.gz |
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
-rw-r--r-- | src/libsyntax/parse/parser.rs | 17 | ||||
-rw-r--r-- | src/test/ui/issue-48636.rs | 17 | ||||
-rw-r--r-- | src/test/ui/issue-48636.stderr | 13 |
3 files changed, 46 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a7a9ce74512..da819adbde6 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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); } } diff --git a/src/test/ui/issue-48636.rs b/src/test/ui/issue-48636.rs new file mode 100644 index 00000000000..03e45d88e6c --- /dev/null +++ b/src/test/ui/issue-48636.rs @@ -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() {} diff --git a/src/test/ui/issue-48636.stderr b/src/test/ui/issue-48636.stderr new file mode 100644 index 00000000000..4e014a5bd1d --- /dev/null +++ b/src/test/ui/issue-48636.stderr @@ -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`. |