From afaa45e0e02d54dfca584a32bf14facaddab1ff8 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Wed, 26 Jun 2024 12:26:15 -0300 Subject: improve identifier naming, remove error id not gonna need error ids for now --- crates/typst/src/diag.rs | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/crates/typst/src/diag.rs b/crates/typst/src/diag.rs index 767418da..6277b991 100644 --- a/crates/typst/src/diag.rs +++ b/crates/typst/src/diag.rs @@ -122,7 +122,7 @@ macro_rules! __warning { ) => { $crate::diag::SourceDiagnostic::warning( $span, - std::option::Option::Some($crate::diag::WarnIdentifier::$id), + std::option::Option::Some($crate::diag::CompilerWarning::$id), $crate::diag::eco_format!($fmt, $($arg),*), ) $(.with_hint($crate::diag::eco_format!($hint, $($hint_arg),*)))* }; @@ -195,7 +195,7 @@ impl SourceDiagnostic { /// Create a new, bare warning. pub fn warning( span: Span, - identifier: Option, + identifier: Option, message: impl Into, ) -> Self { Self { @@ -242,19 +242,14 @@ impl From for SourceDiagnostic { /// Any possible identifier for a diagnostic. #[derive(Debug, Clone, Eq, PartialEq, Hash)] pub enum Identifier { - /// Identifier for a built-in compiler error. - Error(ErrorIdentifier), /// Identifier for a built-in compiler warning. - Warn(WarnIdentifier), + Warn(CompilerWarning), /// Identifier for a warning raised by a package. User(EcoString), } #[derive(Debug, Clone, Eq, PartialEq, Hash)] -pub enum ErrorIdentifier {} - -#[derive(Debug, Clone, Eq, PartialEq, Hash)] -pub enum WarnIdentifier { +pub enum CompilerWarning { UnnecessaryImportRenaming, UnnecessaryStars, UnnecessaryUnderscores, @@ -262,24 +257,24 @@ pub enum WarnIdentifier { UnknownFontFamilies, } -impl WarnIdentifier { +impl CompilerWarning { pub const fn name(&self) -> &'static str { match self { - WarnIdentifier::UnnecessaryImportRenaming => "unnecessary-import-renaming", - WarnIdentifier::UnnecessaryStars => "unnecessary-stars", - WarnIdentifier::UnnecessaryUnderscores => "unnecessary-underscores", - WarnIdentifier::NonConvergingLayout => "non-converging-layout", - WarnIdentifier::UnknownFontFamilies => "unknown-font-families", + CompilerWarning::UnnecessaryImportRenaming => "unnecessary-import-renaming", + CompilerWarning::UnnecessaryStars => "unnecessary-stars", + CompilerWarning::UnnecessaryUnderscores => "unnecessary-underscores", + CompilerWarning::NonConvergingLayout => "non-converging-layout", + CompilerWarning::UnknownFontFamilies => "unknown-font-families", } } pub const fn categories(&self) -> &'_ [&'static str] { match self { - WarnIdentifier::UnnecessaryImportRenaming => &["unnecessary", "syntax"], - WarnIdentifier::UnnecessaryStars => &["unnecessary", "markup"], - WarnIdentifier::UnnecessaryUnderscores => &["unnecessary", "markup"], - WarnIdentifier::NonConvergingLayout => &["layout"], - WarnIdentifier::UnknownFontFamilies => &["fonts"], + CompilerWarning::UnnecessaryImportRenaming => &["unnecessary", "syntax"], + CompilerWarning::UnnecessaryStars => &["unnecessary", "markup"], + CompilerWarning::UnnecessaryUnderscores => &["unnecessary", "markup"], + CompilerWarning::NonConvergingLayout => &["layout"], + CompilerWarning::UnknownFontFamilies => &["fonts"], } } } @@ -290,7 +285,6 @@ impl Identifier { match self { Self::Warn(warning_identifier) => warning_identifier.name(), Self::User(user_identifier) => user_identifier, - Self::Error(_) => unreachable!(), } } } -- cgit v1.2.3