Skip to content
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

fixes rust-lang#56766 #59041

Merged
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
16 changes: 16 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6630,6 +6630,22 @@ impl<'a> Parser<'a> {
self.expect(&token::OpenDelim(token::Brace))?;
let mut trait_items = vec![];
while !self.eat(&token::CloseDelim(token::Brace)) {
if let token::DocComment(_) = self.token {
if self.look_ahead(1,
|tok| tok == &token::Token::CloseDelim(token::Brace)) {
let mut err = self.diagnostic().struct_span_err_with_code(
self.span,
"found a documentation comment that doesn't document anything",
DiagnosticId::Error("E0584".into()),
);
err.help("doc comments must come before what they document, maybe a \
comment was intended with `//`?",
);
err.emit();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For everything between 6636 and 6644 you can replace it with self.span_fatal_err(self.prev_span, Error::UselessDocComment).emit();, like in

s.span_fatal_err(s.prev_span, Error::UselessDocComment).emit();

Copy link
Contributor Author

@saleemjaffer saleemjaffer Mar 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#57333 (comment)

@estebank This is the reason I used struct_span_err_with_code. Do we not need that now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(indeed, this does not seem like it needs to be a fatal error; I concur with @saleemjaffer's choice to use a non-fatal error here.)

self.bump();
continue;
}
}
let mut at_end = false;
match self.parse_trait_item(&mut at_end) {
Ok(item) => trait_items.push(item),
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/parser/doc-inside-trait-item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
trait User{
fn test();
/// empty doc
//~^ ERROR found a documentation comment that doesn't document anything
}
fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/parser/doc-inside-trait-item.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0584]: found a documentation comment that doesn't document anything
--> $DIR/doc-inside-trait-item.rs:3:5
|
LL | /// empty doc
| ^^^^^^^^^^^^^
|
= help: doc comments must come before what they document, maybe a comment was intended with `//`?

error: aborting due to previous error

For more information about this error, try `rustc --explain E0584`.