Rollup merge of #59041 - saleemjaffer:trait_doc_comment_better_error_msg, r=pnkfelix

fixes rust-lang#56766

fixes #56766
This commit is contained in:
Mazdak Farrokhzad 2019-04-01 17:29:53 +02:00 committed by GitHub
commit d2fd3fe957
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View File

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

View File

@ -0,0 +1,6 @@
trait User{
fn test();
/// empty doc
//~^ ERROR found a documentation comment that doesn't document anything
}
fn main() {}

View File

@ -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`.