1
Fork 0

feat/refactor: improve errors in case of ident with number at start

This commit is contained in:
Ezra Shaw 2023-03-07 23:01:26 +13:00
parent 8824994ccd
commit 252e0b3385
No known key found for this signature in database
GPG key ID: 67ABF16FB0ECD870
9 changed files with 68 additions and 45 deletions

View file

@ -939,6 +939,7 @@ pub(crate) struct ExpectedIdentifier {
pub token: Token,
pub suggest_raw: Option<SuggEscapeToUseAsIdentifier>,
pub suggest_remove_comma: Option<SuggRemoveComma>,
pub help_cannot_start_number: Option<HelpIdentifierStartsWithNumber>,
}
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {
@ -975,10 +976,18 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {
sugg.add_to_diagnostic(&mut diag);
}
if let Some(help) = self.help_cannot_start_number {
help.add_to_diagnostic(&mut diag);
}
diag
}
}
#[derive(Subdiagnostic)]
#[help(parse_invalid_identifier_with_leading_number)]
pub(crate) struct HelpIdentifierStartsWithNumber;
pub(crate) struct ExpectedSemi {
pub span: Span,
pub token: Token,
@ -1207,14 +1216,6 @@ pub(crate) struct SelfParamNotFirst {
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_invalid_identifier_with_leading_number)]
pub(crate) struct InvalidIdentiferStartsWithNumber {
#[primary_span]
#[label]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_const_generic_without_braces)]
pub(crate) struct ConstGenericWithoutBraces {