From dda03efa5f68a0cc84e0ac6d0b7f69ac019a9653 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Tue, 10 Sep 2024 11:07:52 -0300 Subject: [PATCH] feat: better error message for misplaced doc comments --- compiler/noirc_frontend/src/parser/errors.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/noirc_frontend/src/parser/errors.rs b/compiler/noirc_frontend/src/parser/errors.rs index ad6f6b928ab..406bcfbf12a 100644 --- a/compiler/noirc_frontend/src/parser/errors.rs +++ b/compiler/noirc_frontend/src/parser/errors.rs @@ -211,8 +211,17 @@ impl<'a> From<&'a ParserError> for Diagnostic { other => Diagnostic::simple_error(format!("{other}"), String::new(), error.span), }, None => { - let primary = error.to_string(); - Diagnostic::simple_error(primary, String::new(), error.span) + if matches!( + error.found.kind(), + TokenKind::InnerDocComment | TokenKind::OuterDocComment + ) { + let primary = "This doc comment doesn't document anything".to_string(); + let secondary = "Consider changing it to a regular `//` comment".to_string(); + Diagnostic::simple_error(primary, secondary, error.span) + } else { + let primary = error.to_string(); + Diagnostic::simple_error(primary, String::new(), error.span) + } } } }