|
1 | 1 | use iter_extended::vecmap; |
2 | 2 |
|
3 | 3 | use crate::{ |
4 | | - parser::{labels::ParsingRuleLabel, Item, ItemKind}, |
| 4 | + parser::{labels::ParsingRuleLabel, Item, ItemKind, ParserErrorReason}, |
5 | 5 | token::{Keyword, Token}, |
6 | 6 | }; |
7 | 7 |
|
@@ -94,6 +94,10 @@ impl<'a> Parser<'a> { |
94 | 94 | let kinds = self.parse_item_kind(); |
95 | 95 | let span = self.span_since(start_span); |
96 | 96 |
|
| 97 | + if kinds.is_empty() && !doc_comments.is_empty() { |
| 98 | + self.push_error(ParserErrorReason::DocCommentDoesNotDocumentAnything, start_span); |
| 99 | + } |
| 100 | + |
97 | 101 | vecmap(kinds, |kind| Item { kind, span, doc_comments: doc_comments.clone() }) |
98 | 102 | } |
99 | 103 |
|
@@ -260,4 +264,18 @@ mod tests { |
260 | 264 | let error = get_single_error(&errors, span); |
261 | 265 | assert_eq!(error.to_string(), "Expected a '}' but found end of input"); |
262 | 266 | } |
| 267 | + |
| 268 | + #[test] |
| 269 | + fn errors_on_trailing_doc_comment() { |
| 270 | + let src = " |
| 271 | + fn foo() {} |
| 272 | + /// doc comment |
| 273 | + ^^^^^^^^^^^^^^^ |
| 274 | + "; |
| 275 | + let (src, span) = get_source_with_error_span(src); |
| 276 | + let (module, errors) = parse_program(&src); |
| 277 | + assert_eq!(module.items.len(), 1); |
| 278 | + let error = get_single_error(&errors, span); |
| 279 | + assert!(error.to_string().contains("Documentation comment does not document anything")); |
| 280 | + } |
263 | 281 | } |
0 commit comments