diff options
Diffstat (limited to 'crates/ra_hir_expand/src')
-rw-r--r-- | crates/ra_hir_expand/src/diagnostics.rs | 19 |
1 files changed, 5 insertions, 14 deletions
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 { | |||
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 | ||
32 | pub trait AstDiagnostic { | 32 | pub trait DiagnosticWithFix { |
33 | type AST; | 33 | type AST; |
34 | fn fix_source(&self, db: &dyn AstDatabase) -> Self::AST; | 34 | fn fix_source(&self, db: &dyn AstDatabase) -> Option<Self::AST>; |
35 | } | ||
36 | |||
37 | impl dyn Diagnostic { | ||
38 | pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { | ||
39 | self.as_any().downcast_ref() | ||
40 | } | ||
41 | } | 35 | } |
42 | 36 | ||
43 | pub struct DiagnosticSink<'a> { | 37 | pub struct DiagnosticSink<'a> { |
@@ -83,12 +77,9 @@ impl<'a> DiagnosticSinkBuilder<'a> { | |||
83 | self | 77 | self |
84 | } | 78 | } |
85 | 79 | ||
86 | pub fn on<D: Diagnostic, F: FnMut(&D) + 'a>(mut self, mut cb: F) -> Self { | 80 | pub fn on<D: Diagnostic, F: FnMut(&D) -> Option<()> + 'a>(mut self, mut cb: F) -> Self { |
87 | let cb = move |diag: &dyn Diagnostic| match diag.downcast_ref::<D>() { | 81 | let cb = move |diag: &dyn Diagnostic| match diag.as_any().downcast_ref::<D>() { |
88 | Some(d) => { | 82 | Some(d) => cb(d).ok_or(()), |
89 | cb(d); | ||
90 | Ok(()) | ||
91 | } | ||
92 | None => Err(()), | 83 | None => Err(()), |
93 | }; | 84 | }; |
94 | self.callbacks.push(Box::new(cb)); | 85 | self.callbacks.push(Box::new(cb)); |