From 1bed654053c9abb0c48cf6d17c8f77c4acec4bc9 Mon Sep 17 00:00:00 2001 From: Pramod Bisht Date: Sat, 21 Apr 2018 18:39:34 +0530 Subject: 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 --- src/libsyntax/parse/parser.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/libsyntax/parse/parser.rs') 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 ) -> 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); } } -- cgit 1.4.1-3-g733a5