From 8146669542dfc887956901b54a453c9a97fee7e3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 18 Aug 2020 18:39:43 +0200 Subject: Add type safety to diagnostic codes --- crates/hir_expand/src/diagnostics.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'crates/hir_expand') diff --git a/crates/hir_expand/src/diagnostics.rs b/crates/hir_expand/src/diagnostics.rs index 6c81b2501..78ccc212c 100644 --- a/crates/hir_expand/src/diagnostics.rs +++ b/crates/hir_expand/src/diagnostics.rs @@ -20,8 +20,17 @@ use syntax::SyntaxNodePtr; use crate::InFile; +#[derive(Copy, Clone, PartialEq)] +pub struct DiagnosticCode(pub &'static str); + +impl DiagnosticCode { + pub fn as_str(&self) -> &str { + self.0 + } +} + pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { - fn name(&self) -> &'static str; + fn code(&self) -> DiagnosticCode; fn message(&self) -> String; /// Used in highlighting and related purposes fn display_source(&self) -> InFile; -- cgit v1.2.3