about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libsyntax/parse/parser.rs16
-rw-r--r--src/test/ui/parser/doc-inside-trait-item.rs6
-rw-r--r--src/test/ui/parser/doc-inside-trait-item.stderr11
3 files changed, 33 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index ae8e57d54de..37360a56395 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -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),
diff --git a/src/test/ui/parser/doc-inside-trait-item.rs b/src/test/ui/parser/doc-inside-trait-item.rs
new file mode 100644
index 00000000000..87b501bd2a2
--- /dev/null
+++ b/src/test/ui/parser/doc-inside-trait-item.rs
@@ -0,0 +1,6 @@
+trait User{
+    fn test();
+    /// empty doc
+    //~^ ERROR found a documentation comment that doesn't document anything
+}
+fn main() {}
diff --git a/src/test/ui/parser/doc-inside-trait-item.stderr b/src/test/ui/parser/doc-inside-trait-item.stderr
new file mode 100644
index 00000000000..261e27b6e0d
--- /dev/null
+++ b/src/test/ui/parser/doc-inside-trait-item.stderr
@@ -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`.