about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-01-21 02:21:58 +0100
committerGitHub <noreply@github.com>2019-01-21 02:21:58 +0100
commit00c60d115cfb979c4ca39bb1ce3afc7bf0548d79 (patch)
tree3d37ba8cb1776840ead8a120a961fe27d56ae435 /src/libsyntax
parent74b8cd4957de3a7208b4a38cb82a0003c832f88a (diff)
parentb97c9641f51c6897ddded240c87e84f065f55588 (diff)
downloadrust-00c60d115cfb979c4ca39bb1ce3afc7bf0548d79.tar.gz
rust-00c60d115cfb979c4ca39bb1ce3afc7bf0548d79.zip
Rollup merge of #57784 - JohnTitor:improve-error-message, r=estebank
Add span for bad doc comment

Fixes #57382

r? @estebank
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/parse/parser.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index e09b7a9dd7b..439eec5b0c4 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -4483,13 +4483,17 @@ impl<'a> Parser<'a> {
     }
 
     /// Emit an expected item after attributes error.
-    fn expected_item_err(&self, attrs: &[Attribute]) {
+    fn expected_item_err(&mut self, attrs: &[Attribute]) -> PResult<'a,  ()> {
         let message = match attrs.last() {
             Some(&Attribute { is_sugared_doc: true, .. }) => "expected item after doc comment",
             _ => "expected item after attributes",
         };
 
-        self.span_err(self.prev_span, message);
+        let mut err = self.diagnostic().struct_span_err(self.prev_span, message);
+        if attrs.last().unwrap().is_sugared_doc {
+            err.span_label(self.prev_span, "this doc comment doesn't document anything");
+        }
+        Err(err)
     }
 
     /// Parse a statement. This stops just before trailing semicolons on everything but items.
@@ -7636,7 +7640,7 @@ impl<'a> Parser<'a> {
             }
             None => {
                 if !attrs.is_empty()  {
-                    self.expected_item_err(&attrs);
+                    self.expected_item_err(&attrs)?;
                 }
 
                 self.unexpected()
@@ -7699,7 +7703,7 @@ impl<'a> Parser<'a> {
         }
 
         if !attributes_allowed && !attrs.is_empty() {
-            self.expected_item_err(&attrs);
+            self.expected_item_err(&attrs)?;
         }
         Ok(None)
     }