Skip to content

Add span for bad doc comment #57784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/doc-before-eof.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: expected item after doc comment
--> $DIR/doc-before-eof.rs:3:1
|
LL | /// hi //~ERROR expected item after doc comment
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this doc comment doesn't document anything

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/parser/doc-before-extern-rbrace.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: expected item after doc comment
--> $DIR/doc-before-extern-rbrace.rs:2:5
|
LL | /// hi
| ^^^^^^
| ^^^^^^ this doc comment doesn't document anything

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/parser/doc-before-mod-rbrace.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: expected item after doc comment
--> $DIR/doc-before-mod-rbrace.rs:4:5
|
LL | /// document
| ^^^^^^^^^^^^
| ^^^^^^^^^^^^ this doc comment doesn't document anything

error: aborting due to previous error