Skip to content

Commit a252123

Browse files
authored
fix: error on trailing doc comment (#7300)
1 parent d327462 commit a252123

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

  • compiler/noirc_frontend/src/parser/parser

compiler/noirc_frontend/src/parser/parser/item.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use iter_extended::vecmap;
22

33
use crate::{
4-
parser::{labels::ParsingRuleLabel, Item, ItemKind},
4+
parser::{labels::ParsingRuleLabel, Item, ItemKind, ParserErrorReason},
55
token::{Keyword, Token},
66
};
77

@@ -94,6 +94,10 @@ impl<'a> Parser<'a> {
9494
let kinds = self.parse_item_kind();
9595
let span = self.span_since(start_span);
9696

97+
if kinds.is_empty() && !doc_comments.is_empty() {
98+
self.push_error(ParserErrorReason::DocCommentDoesNotDocumentAnything, start_span);
99+
}
100+
97101
vecmap(kinds, |kind| Item { kind, span, doc_comments: doc_comments.clone() })
98102
}
99103

@@ -260,4 +264,18 @@ mod tests {
260264
let error = get_single_error(&errors, span);
261265
assert_eq!(error.to_string(), "Expected a '}' but found end of input");
262266
}
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+
}
263281
}

0 commit comments

Comments
 (0)