Skip to content

Commit

Permalink
Rollup merge of rust-lang#59041 - saleemjaffer:trait_doc_comment_bett…
Browse files Browse the repository at this point in the history
…er_error_msg, r=pnkfelix

fixes rust-lang#56766

fixes rust-lang#56766
  • Loading branch information
Centril authored Apr 1, 2019
2 parents 0d01fba + d258481 commit d2fd3fe
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6722,6 +6722,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();
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`.

0 comments on commit d2fd3fe

Please sign in to comment.