Rollup merge of #59041 - saleemjaffer:trait_doc_comment_better_error_msg, r=pnkfelix
fixes rust-lang#56766 fixes #56766
This commit is contained in:
commit
d2fd3fe957
@ -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),
|
||||
|
6
src/test/ui/parser/doc-inside-trait-item.rs
Normal file
6
src/test/ui/parser/doc-inside-trait-item.rs
Normal file
@ -0,0 +1,6 @@
|
||||
trait User{
|
||||
fn test();
|
||||
/// empty doc
|
||||
//~^ ERROR found a documentation comment that doesn't document anything
|
||||
}
|
||||
fn main() {}
|
11
src/test/ui/parser/doc-inside-trait-item.stderr
Normal file
11
src/test/ui/parser/doc-inside-trait-item.stderr
Normal 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`.
|
Loading…
Reference in New Issue
Block a user