Skip to content

Commit 8abb24c

Browse files
authored
Rollup merge of rust-lang#59041 - saleemjaffer:trait_doc_comment_better_error_msg, r=pnkfelix
fixes rust-lang#56766 fixes rust-lang#56766
2 parents 4a9e791 + d258481 commit 8abb24c

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6722,6 +6722,22 @@ impl<'a> Parser<'a> {
67226722
self.expect(&token::OpenDelim(token::Brace))?;
67236723
let mut trait_items = vec![];
67246724
while !self.eat(&token::CloseDelim(token::Brace)) {
6725+
if let token::DocComment(_) = self.token {
6726+
if self.look_ahead(1,
6727+
|tok| tok == &token::Token::CloseDelim(token::Brace)) {
6728+
let mut err = self.diagnostic().struct_span_err_with_code(
6729+
self.span,
6730+
"found a documentation comment that doesn't document anything",
6731+
DiagnosticId::Error("E0584".into()),
6732+
);
6733+
err.help("doc comments must come before what they document, maybe a \
6734+
comment was intended with `//`?",
6735+
);
6736+
err.emit();
6737+
self.bump();
6738+
continue;
6739+
}
6740+
}
67256741
let mut at_end = false;
67266742
match self.parse_trait_item(&mut at_end) {
67276743
Ok(item) => trait_items.push(item),
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
trait User{
2+
fn test();
3+
/// empty doc
4+
//~^ ERROR found a documentation comment that doesn't document anything
5+
}
6+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0584]: found a documentation comment that doesn't document anything
2+
--> $DIR/doc-inside-trait-item.rs:3:5
3+
|
4+
LL | /// empty doc
5+
| ^^^^^^^^^^^^^
6+
|
7+
= help: doc comments must come before what they document, maybe a comment was intended with `//`?
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0584`.

0 commit comments

Comments
 (0)