From 54b3849dfbb2b00741d48a11ef786b363e4d0435 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 4 Feb 2025 14:44:08 -0500 Subject: [PATCH] ruff_db: add more `dyn Diagnostic` impls I found it useful to have the `&dyn Diagnostic` trait impl specifically. I added `Arc` for completeness. (I do kind of wonder if we should be preferring `Arc` over something like `Box` more generally, especially for things with immutable APIs. It would make cloning cheap.) --- crates/ruff_db/src/diagnostic.rs | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/crates/ruff_db/src/diagnostic.rs b/crates/ruff_db/src/diagnostic.rs index 20b04bcb22..4b3be76ab9 100644 --- a/crates/ruff_db/src/diagnostic.rs +++ b/crates/ruff_db/src/diagnostic.rs @@ -375,6 +375,50 @@ impl Diagnostic for Box { } } +impl Diagnostic for &'_ dyn Diagnostic { + fn id(&self) -> DiagnosticId { + (**self).id() + } + + fn message(&self) -> Cow { + (**self).message() + } + + fn file(&self) -> Option { + (**self).file() + } + + fn range(&self) -> Option { + (**self).range() + } + + fn severity(&self) -> Severity { + (**self).severity() + } +} + +impl Diagnostic for std::sync::Arc { + fn id(&self) -> DiagnosticId { + (**self).id() + } + + fn message(&self) -> Cow { + (**self).message() + } + + fn file(&self) -> Option { + (**self).file() + } + + fn range(&self) -> Option { + (**self).range() + } + + fn severity(&self) -> Severity { + (**self).severity() + } +} + #[derive(Debug)] pub struct ParseDiagnostic { file: File,