diff options
-rw-r--r-- | crates/ra_hir_def/src/diagnostics.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/diagnostics.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics.rs | 32 | ||||
-rw-r--r-- | crates/ra_ide/src/diagnostics.rs | 26 |
4 files changed, 31 insertions, 33 deletions
diff --git a/crates/ra_hir_def/src/diagnostics.rs b/crates/ra_hir_def/src/diagnostics.rs index 1d28c24e8..481b13a87 100644 --- a/crates/ra_hir_def/src/diagnostics.rs +++ b/crates/ra_hir_def/src/diagnostics.rs | |||
@@ -15,8 +15,8 @@ pub struct UnresolvedModule { | |||
15 | } | 15 | } |
16 | 16 | ||
17 | impl Diagnostic for UnresolvedModule { | 17 | impl Diagnostic for UnresolvedModule { |
18 | fn name(&self) -> String { | 18 | fn name(&self) -> &'static str { |
19 | "unresolved-module".to_string() | 19 | "unresolved-module" |
20 | } | 20 | } |
21 | fn message(&self) -> String { | 21 | fn message(&self) -> String { |
22 | "unresolved module".to_string() | 22 | "unresolved module".to_string() |
diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs index ef1d61144..507132a13 100644 --- a/crates/ra_hir_expand/src/diagnostics.rs +++ b/crates/ra_hir_expand/src/diagnostics.rs | |||
@@ -21,7 +21,7 @@ use ra_syntax::{SyntaxNode, SyntaxNodePtr}; | |||
21 | use crate::{db::AstDatabase, InFile}; | 21 | use crate::{db::AstDatabase, InFile}; |
22 | 22 | ||
23 | pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { | 23 | pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { |
24 | fn name(&self) -> String; | 24 | fn name(&self) -> &'static str; |
25 | fn message(&self) -> String; | 25 | fn message(&self) -> String; |
26 | fn source(&self) -> InFile<SyntaxNodePtr>; | 26 | fn source(&self) -> InFile<SyntaxNodePtr>; |
27 | fn as_any(&self) -> &(dyn Any + Send + 'static); | 27 | fn as_any(&self) -> &(dyn Any + Send + 'static); |
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 0b3e16ae7..56acd3bbf 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs | |||
@@ -33,8 +33,8 @@ pub struct NoSuchField { | |||
33 | } | 33 | } |
34 | 34 | ||
35 | impl Diagnostic for NoSuchField { | 35 | impl Diagnostic for NoSuchField { |
36 | fn name(&self) -> String { | 36 | fn name(&self) -> &'static str { |
37 | "no-such-field".to_string() | 37 | "no-such-field" |
38 | } | 38 | } |
39 | 39 | ||
40 | fn message(&self) -> String { | 40 | fn message(&self) -> String { |
@@ -68,8 +68,8 @@ pub struct MissingFields { | |||
68 | } | 68 | } |
69 | 69 | ||
70 | impl Diagnostic for MissingFields { | 70 | impl Diagnostic for MissingFields { |
71 | fn name(&self) -> String { | 71 | fn name(&self) -> &'static str { |
72 | "missing-structure-fields".to_string() | 72 | "missing-structure-fields" |
73 | } | 73 | } |
74 | fn message(&self) -> String { | 74 | fn message(&self) -> String { |
75 | let mut buf = String::from("Missing structure fields:\n"); | 75 | let mut buf = String::from("Missing structure fields:\n"); |
@@ -104,8 +104,8 @@ pub struct MissingPatFields { | |||
104 | } | 104 | } |
105 | 105 | ||
106 | impl Diagnostic for MissingPatFields { | 106 | impl Diagnostic for MissingPatFields { |
107 | fn name(&self) -> String { | 107 | fn name(&self) -> &'static str { |
108 | "missing-pat-fields".to_string() | 108 | "missing-pat-fields" |
109 | } | 109 | } |
110 | fn message(&self) -> String { | 110 | fn message(&self) -> String { |
111 | let mut buf = String::from("Missing structure fields:\n"); | 111 | let mut buf = String::from("Missing structure fields:\n"); |
@@ -130,8 +130,8 @@ pub struct MissingMatchArms { | |||
130 | } | 130 | } |
131 | 131 | ||
132 | impl Diagnostic for MissingMatchArms { | 132 | impl Diagnostic for MissingMatchArms { |
133 | fn name(&self) -> String { | 133 | fn name(&self) -> &'static str { |
134 | "missing-match-arm".to_string() | 134 | "missing-match-arm" |
135 | } | 135 | } |
136 | fn message(&self) -> String { | 136 | fn message(&self) -> String { |
137 | String::from("Missing match arm") | 137 | String::from("Missing match arm") |
@@ -151,8 +151,8 @@ pub struct MissingOkInTailExpr { | |||
151 | } | 151 | } |
152 | 152 | ||
153 | impl Diagnostic for MissingOkInTailExpr { | 153 | impl Diagnostic for MissingOkInTailExpr { |
154 | fn name(&self) -> String { | 154 | fn name(&self) -> &'static str { |
155 | "missing-ok-in-tail-expr".to_string() | 155 | "missing-ok-in-tail-expr" |
156 | } | 156 | } |
157 | fn message(&self) -> String { | 157 | fn message(&self) -> String { |
158 | "wrap return expression in Ok".to_string() | 158 | "wrap return expression in Ok".to_string() |
@@ -182,8 +182,8 @@ pub struct BreakOutsideOfLoop { | |||
182 | } | 182 | } |
183 | 183 | ||
184 | impl Diagnostic for BreakOutsideOfLoop { | 184 | impl Diagnostic for BreakOutsideOfLoop { |
185 | fn name(&self) -> String { | 185 | fn name(&self) -> &'static str { |
186 | "break-outside-of-loop".to_string() | 186 | "break-outside-of-loop" |
187 | } | 187 | } |
188 | fn message(&self) -> String { | 188 | fn message(&self) -> String { |
189 | "break outside of loop".to_string() | 189 | "break outside of loop".to_string() |
@@ -213,8 +213,8 @@ pub struct MissingUnsafe { | |||
213 | } | 213 | } |
214 | 214 | ||
215 | impl Diagnostic for MissingUnsafe { | 215 | impl Diagnostic for MissingUnsafe { |
216 | fn name(&self) -> String { | 216 | fn name(&self) -> &'static str { |
217 | "missing-unsafe".to_string() | 217 | "missing-unsafe" |
218 | } | 218 | } |
219 | fn message(&self) -> String { | 219 | fn message(&self) -> String { |
220 | format!("This operation is unsafe and requires an unsafe function or block") | 220 | format!("This operation is unsafe and requires an unsafe function or block") |
@@ -246,8 +246,8 @@ pub struct MismatchedArgCount { | |||
246 | } | 246 | } |
247 | 247 | ||
248 | impl Diagnostic for MismatchedArgCount { | 248 | impl Diagnostic for MismatchedArgCount { |
249 | fn name(&self) -> String { | 249 | fn name(&self) -> &'static str { |
250 | "mismatched-arg-count".to_string() | 250 | "mismatched-arg-count" |
251 | } | 251 | } |
252 | fn message(&self) -> String { | 252 | fn message(&self) -> String { |
253 | let s = if self.expected == 1 { "" } else { "s" }; | 253 | let s = if self.expected == 1 { "" } else { "s" }; |
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index 8e011a40d..d97bde939 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs | |||
@@ -63,7 +63,7 @@ pub(crate) fn diagnostics( | |||
63 | .into(), | 63 | .into(), |
64 | ); | 64 | ); |
65 | res.borrow_mut().push(Diagnostic { | 65 | res.borrow_mut().push(Diagnostic { |
66 | name: Some(d.name()), | 66 | name: Some(d.name().into()), |
67 | range: sema.diagnostics_range(d).range, | 67 | range: sema.diagnostics_range(d).range, |
68 | message: d.message(), | 68 | message: d.message(), |
69 | severity: Severity::Error, | 69 | severity: Severity::Error, |
@@ -98,7 +98,7 @@ pub(crate) fn diagnostics( | |||
98 | }; | 98 | }; |
99 | 99 | ||
100 | res.borrow_mut().push(Diagnostic { | 100 | res.borrow_mut().push(Diagnostic { |
101 | name: Some(d.name()), | 101 | name: Some(d.name().into()), |
102 | range: sema.diagnostics_range(d).range, | 102 | range: sema.diagnostics_range(d).range, |
103 | message: d.message(), | 103 | message: d.message(), |
104 | severity: Severity::Error, | 104 | severity: Severity::Error, |
@@ -112,7 +112,7 @@ pub(crate) fn diagnostics( | |||
112 | let source_change = SourceFileEdit { file_id, edit }.into(); | 112 | let source_change = SourceFileEdit { file_id, edit }.into(); |
113 | let fix = Fix::new("Wrap with ok", source_change); | 113 | let fix = Fix::new("Wrap with ok", source_change); |
114 | res.borrow_mut().push(Diagnostic { | 114 | res.borrow_mut().push(Diagnostic { |
115 | name: Some(d.name()), | 115 | name: Some(d.name().into()), |
116 | range: sema.diagnostics_range(d).range, | 116 | range: sema.diagnostics_range(d).range, |
117 | message: d.message(), | 117 | message: d.message(), |
118 | severity: Severity::Error, | 118 | severity: Severity::Error, |
@@ -121,7 +121,7 @@ pub(crate) fn diagnostics( | |||
121 | }) | 121 | }) |
122 | .on::<hir::diagnostics::NoSuchField, _>(|d| { | 122 | .on::<hir::diagnostics::NoSuchField, _>(|d| { |
123 | res.borrow_mut().push(Diagnostic { | 123 | res.borrow_mut().push(Diagnostic { |
124 | name: Some(d.name()), | 124 | name: Some(d.name().into()), |
125 | range: sema.diagnostics_range(d).range, | 125 | range: sema.diagnostics_range(d).range, |
126 | message: d.message(), | 126 | message: d.message(), |
127 | severity: Severity::Error, | 127 | severity: Severity::Error, |
@@ -133,8 +133,8 @@ pub(crate) fn diagnostics( | |||
133 | 133 | ||
134 | if !analysis_config.disabled_diagnostics.is_empty() { | 134 | if !analysis_config.disabled_diagnostics.is_empty() { |
135 | // Do not collect disabled diagnostics. | 135 | // Do not collect disabled diagnostics. |
136 | sink_builder = sink_builder | 136 | sink_builder = |
137 | .filter(|diag| !analysis_config.disabled_diagnostics.contains(&diag.name())); | 137 | sink_builder.filter(|diag| !analysis_config.disabled_diagnostics.contains(diag.name())); |
138 | } | 138 | } |
139 | 139 | ||
140 | // Finalize the `DiagnosticSink` building process. | 140 | // Finalize the `DiagnosticSink` building process. |
@@ -142,7 +142,7 @@ pub(crate) fn diagnostics( | |||
142 | // Diagnostics not handled above get no fix and default treatment. | 142 | // Diagnostics not handled above get no fix and default treatment. |
143 | .build(|d| { | 143 | .build(|d| { |
144 | res.borrow_mut().push(Diagnostic { | 144 | res.borrow_mut().push(Diagnostic { |
145 | name: Some(d.name()), | 145 | name: Some(d.name().into()), |
146 | message: d.message(), | 146 | message: d.message(), |
147 | range: sema.diagnostics_range(d).range, | 147 | range: sema.diagnostics_range(d).range, |
148 | severity: Severity::Error, | 148 | severity: Severity::Error, |
@@ -313,6 +313,7 @@ fn check_struct_shorthand_initialization( | |||
313 | 313 | ||
314 | #[cfg(test)] | 314 | #[cfg(test)] |
315 | mod tests { | 315 | mod tests { |
316 | use std::collections::HashSet; | ||
316 | use stdx::trim_indent; | 317 | use stdx::trim_indent; |
317 | use test_utils::assert_eq_text; | 318 | use test_utils::assert_eq_text; |
318 | 319 | ||
@@ -385,12 +386,9 @@ mod tests { | |||
385 | 386 | ||
386 | /// Takes a multi-file input fixture with annotated cursor position and the list of disabled diagnostics, | 387 | /// Takes a multi-file input fixture with annotated cursor position and the list of disabled diagnostics, |
387 | /// and checks that provided diagnostics aren't spawned during analysis. | 388 | /// and checks that provided diagnostics aren't spawned during analysis. |
388 | fn check_disabled_diagnostics( | 389 | fn check_disabled_diagnostics(ra_fixture: &str, disabled_diagnostics: &[&'static str]) { |
389 | ra_fixture: &str, | 390 | let disabled_diagnostics: HashSet<_> = |
390 | disabled_diagnostics: impl IntoIterator<Item = String>, | 391 | disabled_diagnostics.into_iter().map(|diag| diag.to_string()).collect(); |
391 | ) { | ||
392 | let disabled_diagnostics: std::collections::HashSet<_> = | ||
393 | disabled_diagnostics.into_iter().collect(); | ||
394 | 392 | ||
395 | let mock = MockAnalysis::with_files(ra_fixture); | 393 | let mock = MockAnalysis::with_files(ra_fixture); |
396 | let files = mock.files().map(|(it, _)| it).collect::<Vec<_>>(); | 394 | let files = mock.files().map(|(it, _)| it).collect::<Vec<_>>(); |
@@ -871,6 +869,6 @@ struct Foo { | |||
871 | 869 | ||
872 | #[test] | 870 | #[test] |
873 | fn test_disabled_diagnostics() { | 871 | fn test_disabled_diagnostics() { |
874 | check_disabled_diagnostics(r#"mod foo;"#, vec!["unresolved-module".to_string()]); | 872 | check_disabled_diagnostics(r#"mod foo;"#, &vec!["unresolved-module"]); |
875 | } | 873 | } |
876 | } | 874 | } |