From 5cf9742e5ea29a2f1f7075b5486c2fdf679b9ad7 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Thu, 22 Dec 2022 18:48:19 +0100 Subject: [PATCH] Move tuple-index hint as diagnostic's help --- crates/aiken-lang/src/parser/error.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/aiken-lang/src/parser/error.rs b/crates/aiken-lang/src/parser/error.rs index 0d93b280..5a83deff 100644 --- a/crates/aiken-lang/src/parser/error.rs +++ b/crates/aiken-lang/src/parser/error.rs @@ -26,7 +26,7 @@ impl ParseError { } pub fn invalid_tuple_index(span: Span, index: u32, suffix: Option) -> Self { - let hint = suffix.map(|suffix| format!("{index}{suffix}")); + let hint = suffix.map(|suffix| format!("Did you mean '{index}{suffix}'?")); Self { kind: ErrorKind::InvalidTupleIndex { hint }, span, @@ -94,8 +94,12 @@ pub enum ErrorKind { }, #[error("No end branch")] NoEndBranch, - #[error("Invalid tuple index{}", hint.as_ref().map(|s| format!("; did you mean '{s}' ?")).unwrap_or_default())] - InvalidTupleIndex { hint: Option }, + #[error("Invalid tuple index")] + #[diagnostic()] + InvalidTupleIndex { + #[help] + hint: Option, + }, } #[derive(Debug, PartialEq, Eq, Hash, Diagnostic, thiserror::Error)]