aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/diagnostics.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-03-23 17:41:59 +0000
committerAleksey Kladov <[email protected]>2019-03-25 07:52:50 +0000
commit79df62bc742afa33dcf5bedefd60860ca296b9da (patch)
treec917097b30909a273ed28bd92d46d402ec59e367 /crates/ra_hir/src/diagnostics.rs
parent3fb88e95aa5e122a521beec766d5b1264ca4de3b (diff)
cleanup
Diffstat (limited to 'crates/ra_hir/src/diagnostics.rs')
-rw-r--r--crates/ra_hir/src/diagnostics.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs
index e8bb1ed92..d6b28159e 100644
--- a/crates/ra_hir/src/diagnostics.rs
+++ b/crates/ra_hir/src/diagnostics.rs
@@ -8,19 +8,19 @@ use relative_path::RelativePathBuf;
8/// Diagnostic defines hir API for errors and warnings. 8/// Diagnostic defines hir API for errors and warnings.
9/// 9///
10/// It is used as a `dyn` object, which you can downcast to a concrete 10/// It is used as a `dyn` object, which you can downcast to a concrete
11/// diagnostic. Diagnostics are structured, meaning that they include rich 11/// diagnostic. DiagnosticSink are structured, meaning that they include rich
12/// information which can be used by IDE to create fixes. Diagnostics are 12/// information which can be used by IDE to create fixes. DiagnosticSink are
13/// expressed in terms of macro-expanded syntax tree nodes (so, it's a bad idea 13/// expressed in terms of macro-expanded syntax tree nodes (so, it's a bad idea
14/// to diagnostic in a salsa value). 14/// to diagnostic in a salsa value).
15/// 15///
16/// Internally, various subsystems of hir produce diagnostics specific to a 16/// Internally, various subsystems of hir produce diagnostics specific to a
17/// subsytem (typically, an `enum`), which are safe to store in salsa but do not 17/// subsystem (typically, an `enum`), which are safe to store in salsa but do not
18/// include source locations. Such internal diagnostic are transformed into an 18/// include source locations. Such internal diagnostic are transformed into an
19/// instance of `Diagnostic` on demand. 19/// instance of `Diagnostic` on demand.
20pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { 20pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
21 fn message(&self) -> String;
21 fn file(&self) -> HirFileId; 22 fn file(&self) -> HirFileId;
22 fn syntax_node(&self) -> SyntaxNodePtr; 23 fn syntax_node(&self) -> SyntaxNodePtr;
23 fn message(&self) -> String;
24 fn as_any(&self) -> &(Any + Send + 'static); 24 fn as_any(&self) -> &(Any + Send + 'static);
25} 25}
26 26
@@ -31,17 +31,17 @@ impl dyn Diagnostic {
31} 31}
32 32
33#[derive(Debug, Default)] 33#[derive(Debug, Default)]
34pub struct Diagnostics { 34pub struct DiagnosticSink {
35 data: Vec<Box<dyn Diagnostic>>, 35 data: Vec<Box<dyn Diagnostic>>,
36} 36}
37 37
38impl Diagnostics { 38impl DiagnosticSink {
39 pub fn push(&mut self, d: impl Diagnostic) { 39 pub fn push(&mut self, d: impl Diagnostic) {
40 self.data.push(Box::new(d)) 40 self.data.push(Box::new(d))
41 } 41 }
42 42
43 pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'a dyn Diagnostic> + 'a { 43 pub fn into_diagnostics(self) -> Vec<Box<dyn Diagnostic>> {
44 self.data.iter().map(|it| it.as_ref()) 44 self.data
45 } 45 }
46} 46}
47 47
@@ -52,15 +52,15 @@ pub struct NoSuchField {
52} 52}
53 53
54impl Diagnostic for NoSuchField { 54impl Diagnostic for NoSuchField {
55 fn message(&self) -> String {
56 "no such field".to_string()
57 }
55 fn file(&self) -> HirFileId { 58 fn file(&self) -> HirFileId {
56 self.file 59 self.file
57 } 60 }
58 fn syntax_node(&self) -> SyntaxNodePtr { 61 fn syntax_node(&self) -> SyntaxNodePtr {
59 self.field.into() 62 self.field.into()
60 } 63 }
61 fn message(&self) -> String {
62 "no such field".to_string()
63 }
64 fn as_any(&self) -> &(Any + Send + 'static) { 64 fn as_any(&self) -> &(Any + Send + 'static) {
65 self 65 self
66 } 66 }
@@ -74,15 +74,15 @@ pub struct UnresolvedModule {
74} 74}
75 75
76impl Diagnostic for UnresolvedModule { 76impl Diagnostic for UnresolvedModule {
77 fn message(&self) -> String {
78 "unresolved module".to_string()
79 }
77 fn file(&self) -> HirFileId { 80 fn file(&self) -> HirFileId {
78 self.file 81 self.file
79 } 82 }
80 fn syntax_node(&self) -> SyntaxNodePtr { 83 fn syntax_node(&self) -> SyntaxNodePtr {
81 self.decl.into() 84 self.decl.into()
82 } 85 }
83 fn message(&self) -> String {
84 "unresolved module".to_string()
85 }
86 fn as_any(&self) -> &(Any + Send + 'static) { 86 fn as_any(&self) -> &(Any + Send + 'static) {
87 self 87 self
88 } 88 }