From 936861993935d5b2c78b953e2f4b719e1992bd73 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 10 Aug 2020 22:53:10 +0300 Subject: Make the fix AST source Optional --- crates/ra_hir_expand/src/diagnostics.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'crates/ra_hir_expand/src') diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs index 2b74473ce..62a09a73a 100644 --- a/crates/ra_hir_expand/src/diagnostics.rs +++ b/crates/ra_hir_expand/src/diagnostics.rs @@ -29,15 +29,9 @@ pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { } } -pub trait AstDiagnostic { +pub trait DiagnosticWithFix { type AST; - fn fix_source(&self, db: &dyn AstDatabase) -> Self::AST; -} - -impl dyn Diagnostic { - pub fn downcast_ref(&self) -> Option<&D> { - self.as_any().downcast_ref() - } + fn fix_source(&self, db: &dyn AstDatabase) -> Option; } pub struct DiagnosticSink<'a> { @@ -83,12 +77,9 @@ impl<'a> DiagnosticSinkBuilder<'a> { self } - pub fn on(mut self, mut cb: F) -> Self { - let cb = move |diag: &dyn Diagnostic| match diag.downcast_ref::() { - Some(d) => { - cb(d); - Ok(()) - } + pub fn on Option<()> + 'a>(mut self, mut cb: F) -> Self { + let cb = move |diag: &dyn Diagnostic| match diag.as_any().downcast_ref::() { + Some(d) => cb(d).ok_or(()), None => Err(()), }; self.callbacks.push(Box::new(cb)); -- cgit v1.2.3