From 90e87e077114d3431bda9fa64028a4e525e0dd64 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 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/compiler/noirc_frontend/src/parser/errors.rs b/compiler/noirc_frontend/src/parser/errors.rs index ad6f6b928ab..6ba4cb68500 100644 --- a/compiler/noirc_frontend/src/parser/errors.rs +++ b/compiler/noirc_frontend/src/parser/errors.rs @@ -1,6 +1,7 @@ use crate::ast::{Expression, IntegerBitSize}; use crate::lexer::errors::LexerErrorKind; use crate::lexer::token::Token; +use crate::token::TokenKind; use small_ord_set::SmallOrdSet; use thiserror::Error; @@ -211,8 +212,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) + } } } }