diff options
Diffstat (limited to 'crates/ra_hir/src/diagnostics.rs')
-rw-r--r-- | crates/ra_hir/src/diagnostics.rs | 28 |
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. |
20 | pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { | 20 | pub 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)] |
34 | pub struct Diagnostics { | 34 | pub struct DiagnosticSink { |
35 | data: Vec<Box<dyn Diagnostic>>, | 35 | data: Vec<Box<dyn Diagnostic>>, |
36 | } | 36 | } |
37 | 37 | ||
38 | impl Diagnostics { | 38 | impl 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 | ||
54 | impl Diagnostic for NoSuchField { | 54 | impl 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 | ||
76 | impl Diagnostic for UnresolvedModule { | 76 | impl 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 | } |