about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-04-23 01:36:51 +0000
committerbors <bors@rust-lang.org>2018-04-23 01:36:51 +0000
commit2c57826b9254288f40909615ced85a171f96e95c (patch)
treefa9d059fc6dafa02fe079f27ba9d4a765719e449 /src/libsyntax/parse
parente02868793bdb0e83d2ecee295bdc16f6b2e5a142 (diff)
parent1bed654053c9abb0c48cf6d17c8f77c4acec4bc9 (diff)
downloadrust-2c57826b9254288f40909615ced85a171f96e95c.tar.gz
rust-2c57826b9254288f40909615ced85a171f96e95c.zip
Auto merge of #48946 - PramodBisht:issues/48636, r=estebank
Doc comments present after a particular syntax error cause an unhelpful error message to be output.

fixed: #48636

r? @estebank
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 3e1de923695..9fa3952ca80 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -5759,18 +5759,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);
                 }
             }