Move tuple-index hint as diagnostic's help

This commit is contained in:
KtorZ 2022-12-22 18:48:19 +01:00
parent 168196f903
commit 5cf9742e5e
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
1 changed files with 7 additions and 3 deletions

View File

@ -26,7 +26,7 @@ impl ParseError {
} }
pub fn invalid_tuple_index(span: Span, index: u32, suffix: Option<String>) -> Self { pub fn invalid_tuple_index(span: Span, index: u32, suffix: Option<String>) -> Self {
let hint = suffix.map(|suffix| format!("{index}{suffix}")); let hint = suffix.map(|suffix| format!("Did you mean '{index}{suffix}'?"));
Self { Self {
kind: ErrorKind::InvalidTupleIndex { hint }, kind: ErrorKind::InvalidTupleIndex { hint },
span, span,
@ -94,8 +94,12 @@ pub enum ErrorKind {
}, },
#[error("No end branch")] #[error("No end branch")]
NoEndBranch, NoEndBranch,
#[error("Invalid tuple index{}", hint.as_ref().map(|s| format!("; did you mean '{s}' ?")).unwrap_or_default())] #[error("Invalid tuple index")]
InvalidTupleIndex { hint: Option<String> }, #[diagnostic()]
InvalidTupleIndex {
#[help]
hint: Option<String>,
},
} }
#[derive(Debug, PartialEq, Eq, Hash, Diagnostic, thiserror::Error)] #[derive(Debug, PartialEq, Eq, Hash, Diagnostic, thiserror::Error)]