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:
commit
00c60d115c
4 changed files with 11 additions and 7 deletions
|
@ -4483,13 +4483,17 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Emit an expected item after attributes error.
|
/// 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() {
|
let message = match attrs.last() {
|
||||||
Some(&Attribute { is_sugared_doc: true, .. }) => "expected item after doc comment",
|
Some(&Attribute { is_sugared_doc: true, .. }) => "expected item after doc comment",
|
||||||
_ => "expected item after attributes",
|
_ => "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.
|
/// Parse a statement. This stops just before trailing semicolons on everything but items.
|
||||||
|
@ -7636,7 +7640,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
if !attrs.is_empty() {
|
if !attrs.is_empty() {
|
||||||
self.expected_item_err(&attrs);
|
self.expected_item_err(&attrs)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.unexpected()
|
self.unexpected()
|
||||||
|
@ -7699,7 +7703,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !attributes_allowed && !attrs.is_empty() {
|
if !attributes_allowed && !attrs.is_empty() {
|
||||||
self.expected_item_err(&attrs);
|
self.expected_item_err(&attrs)?;
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ error: expected item after doc comment
|
||||||
--> $DIR/doc-before-eof.rs:3:1
|
--> $DIR/doc-before-eof.rs:3:1
|
||||||
|
|
|
|
||||||
LL | /// hi //~ERROR expected item after doc comment
|
LL | /// hi //~ERROR expected item after doc comment
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this doc comment doesn't document anything
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ error: expected item after doc comment
|
||||||
--> $DIR/doc-before-extern-rbrace.rs:2:5
|
--> $DIR/doc-before-extern-rbrace.rs:2:5
|
||||||
|
|
|
|
||||||
LL | /// hi
|
LL | /// hi
|
||||||
| ^^^^^^
|
| ^^^^^^ this doc comment doesn't document anything
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ error: expected item after doc comment
|
||||||
--> $DIR/doc-before-mod-rbrace.rs:4:5
|
--> $DIR/doc-before-mod-rbrace.rs:4:5
|
||||||
|
|
|
|
||||||
LL | /// document
|
LL | /// document
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^ this doc comment doesn't document anything
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue