Rollup merge of #57784 - JohnTitor:improve-error-message, r=estebank

Add span for bad doc comment

Fixes #57382

r? @estebank
This commit is contained in:
Mazdak Farrokhzad
2019-01-21 02:21:58 +01:00
committed by GitHub
4 changed files with 11 additions and 7 deletions

View File

@@ -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)
}