diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1e4a26b353759..1fdbe19183acc 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5940,6 +5940,14 @@ 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)) { + self.span_fatal_err(self.span, Error::UselessDocComment).emit(); + self.bump(); + continue; + } + } + let mut at_end = false; match self.parse_trait_item(&mut at_end) { Ok(item) => trait_items.push(item), @@ -7676,7 +7684,7 @@ impl<'a> Parser<'a> { &mut self.token_cursor.stack[prev].last_token }; - // Pull our the toekns that we've collected from the call to `f` above + // Pull our the tokens that we've collected from the call to `f` above let mut collected_tokens = match *last_token { LastToken::Collecting(ref mut v) => mem::replace(v, Vec::new()), LastToken::Was(_) => panic!("our vector went away?"), diff --git a/src/test/ui/useless-doc-comment/trait-impl.rs b/src/test/ui/useless-doc-comment/trait-impl.rs new file mode 100644 index 0000000000000..a41054abcecd5 --- /dev/null +++ b/src/test/ui/useless-doc-comment/trait-impl.rs @@ -0,0 +1,14 @@ +//! issue #56766 +//! +//! invalid doc comment at the end of a trait declaration + +trait Foo { + /// + fn foo(&self); + /// I am not documenting anything + //~^ ERROR: found a documentation comment that doesn't document anything [E0585] +} + +fn main() { + +} diff --git a/src/test/ui/useless-doc-comment/trait-impl.stderr b/src/test/ui/useless-doc-comment/trait-impl.stderr new file mode 100644 index 0000000000000..aede7909adec6 --- /dev/null +++ b/src/test/ui/useless-doc-comment/trait-impl.stderr @@ -0,0 +1,11 @@ +error[E0585]: found a documentation comment that doesn't document anything + --> $DIR/trait-impl.rs:8:5 + | +LL | /// I am not documenting anything + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = 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 E0585`.