aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-08-10 20:53:10 +0100
committerKirill Bulatov <[email protected]>2020-08-11 13:09:08 +0100
commit936861993935d5b2c78b953e2f4b719e1992bd73 (patch)
tree93f3e8392946b8cb7df98faeb96088dcf82c0db8 /crates/ra_hir_expand
parent9963f43d51071ea02f8f6d490b9c49882034b42c (diff)
Make the fix AST source Optional
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r--crates/ra_hir_expand/src/diagnostics.rs19
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
32pub trait AstDiagnostic { 32pub 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
37impl dyn Diagnostic {
38 pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> {
39 self.as_any().downcast_ref()
40 }
41} 35}
42 36
43pub struct DiagnosticSink<'a> { 37pub 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));