diff options
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/test_db.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 26 |
3 files changed, 18 insertions, 19 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 6eafdc8f6..0f8522021 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs | |||
@@ -4,6 +4,7 @@ use std::any::Any; | |||
4 | 4 | ||
5 | use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; | 5 | use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; |
6 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; | 6 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; |
7 | use stdx::format_to; | ||
7 | 8 | ||
8 | pub use hir_def::diagnostics::UnresolvedModule; | 9 | pub use hir_def::diagnostics::UnresolvedModule; |
9 | pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; | 10 | pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; |
@@ -37,12 +38,11 @@ pub struct MissingFields { | |||
37 | 38 | ||
38 | impl Diagnostic for MissingFields { | 39 | impl Diagnostic for MissingFields { |
39 | fn message(&self) -> String { | 40 | fn message(&self) -> String { |
40 | use std::fmt::Write; | 41 | let mut buf = String::from("Missing structure fields:\n"); |
41 | let mut message = String::from("Missing structure fields:\n"); | ||
42 | for field in &self.missed_fields { | 42 | for field in &self.missed_fields { |
43 | writeln!(message, "- {}", field).unwrap(); | 43 | format_to!(buf, "- {}", field); |
44 | } | 44 | } |
45 | message | 45 | buf |
46 | } | 46 | } |
47 | fn source(&self) -> InFile<SyntaxNodePtr> { | 47 | fn source(&self) -> InFile<SyntaxNodePtr> { |
48 | InFile { file_id: self.file, value: self.field_list.into() } | 48 | InFile { file_id: self.file, value: self.field_list.into() } |
diff --git a/crates/ra_hir_ty/src/test_db.rs b/crates/ra_hir_ty/src/test_db.rs index 5bbeabf51..208096aab 100644 --- a/crates/ra_hir_ty/src/test_db.rs +++ b/crates/ra_hir_ty/src/test_db.rs | |||
@@ -10,6 +10,7 @@ use hir_expand::{db::AstDatabase, diagnostics::DiagnosticSink}; | |||
10 | use ra_db::{ | 10 | use ra_db::{ |
11 | salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, SourceDatabase, Upcast, | 11 | salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, SourceDatabase, Upcast, |
12 | }; | 12 | }; |
13 | use stdx::format_to; | ||
13 | 14 | ||
14 | use crate::{db::HirDatabase, expr::ExprValidator}; | 15 | use crate::{db::HirDatabase, expr::ExprValidator}; |
15 | 16 | ||
@@ -131,7 +132,7 @@ impl TestDB { | |||
131 | for f in fns { | 132 | for f in fns { |
132 | let infer = self.infer(f.into()); | 133 | let infer = self.infer(f.into()); |
133 | let mut sink = DiagnosticSink::new(|d| { | 134 | let mut sink = DiagnosticSink::new(|d| { |
134 | buf += &format!("{:?}: {}\n", d.syntax_node(self).text(), d.message()); | 135 | format_to!(buf, "{:?}: {}\n", d.syntax_node(self).text(), d.message()); |
135 | }); | 136 | }); |
136 | infer.add_diagnostics(self, f, &mut sink); | 137 | infer.add_diagnostics(self, f, &mut sink); |
137 | let mut validator = ExprValidator::new(f, infer, &mut sink); | 138 | let mut validator = ExprValidator::new(f, infer, &mut sink); |
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 7e9547340..027e5a8f8 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -7,7 +7,6 @@ mod traits; | |||
7 | mod method_resolution; | 7 | mod method_resolution; |
8 | mod macros; | 8 | mod macros; |
9 | 9 | ||
10 | use std::fmt::Write; | ||
11 | use std::sync::Arc; | 10 | use std::sync::Arc; |
12 | 11 | ||
13 | use hir_def::{ | 12 | use hir_def::{ |
@@ -26,6 +25,7 @@ use ra_syntax::{ | |||
26 | algo, | 25 | algo, |
27 | ast::{self, AstNode}, | 26 | ast::{self, AstNode}, |
28 | }; | 27 | }; |
28 | use stdx::format_to; | ||
29 | 29 | ||
30 | use crate::{db::HirDatabase, display::HirDisplay, test_db::TestDB, InferenceResult}; | 30 | use crate::{db::HirDatabase, display::HirDisplay, test_db::TestDB, InferenceResult}; |
31 | 31 | ||
@@ -63,7 +63,7 @@ fn infer(ra_fixture: &str) -> String { | |||
63 | fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | 63 | fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { |
64 | let (db, file_id) = TestDB::with_single_file(content); | 64 | let (db, file_id) = TestDB::with_single_file(content); |
65 | 65 | ||
66 | let mut acc = String::new(); | 66 | let mut buf = String::new(); |
67 | 67 | ||
68 | let mut infer_def = |inference_result: Arc<InferenceResult>, | 68 | let mut infer_def = |inference_result: Arc<InferenceResult>, |
69 | body_source_map: Arc<BodySourceMap>| { | 69 | body_source_map: Arc<BodySourceMap>| { |
@@ -106,15 +106,14 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | |||
106 | (src_ptr.value.range(), node.text().to_string().replace("\n", " ")) | 106 | (src_ptr.value.range(), node.text().to_string().replace("\n", " ")) |
107 | }; | 107 | }; |
108 | let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; | 108 | let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; |
109 | writeln!( | 109 | format_to!( |
110 | acc, | 110 | buf, |
111 | "{}{} '{}': {}", | 111 | "{}{} '{}': {}\n", |
112 | macro_prefix, | 112 | macro_prefix, |
113 | range, | 113 | range, |
114 | ellipsize(text, 15), | 114 | ellipsize(text, 15), |
115 | ty.display(&db) | 115 | ty.display(&db) |
116 | ) | 116 | ); |
117 | .unwrap(); | ||
118 | } | 117 | } |
119 | if include_mismatches { | 118 | if include_mismatches { |
120 | mismatches.sort_by_key(|(src_ptr, _)| { | 119 | mismatches.sort_by_key(|(src_ptr, _)| { |
@@ -123,15 +122,14 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | |||
123 | for (src_ptr, mismatch) in &mismatches { | 122 | for (src_ptr, mismatch) in &mismatches { |
124 | let range = src_ptr.value.range(); | 123 | let range = src_ptr.value.range(); |
125 | let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; | 124 | let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; |
126 | writeln!( | 125 | format_to!( |
127 | acc, | 126 | buf, |
128 | "{}{}: expected {}, got {}", | 127 | "{}{}: expected {}, got {}\n", |
129 | macro_prefix, | 128 | macro_prefix, |
130 | range, | 129 | range, |
131 | mismatch.expected.display(&db), | 130 | mismatch.expected.display(&db), |
132 | mismatch.actual.display(&db), | 131 | mismatch.actual.display(&db), |
133 | ) | 132 | ); |
134 | .unwrap(); | ||
135 | } | 133 | } |
136 | } | 134 | } |
137 | }; | 135 | }; |
@@ -158,8 +156,8 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | |||
158 | infer_def(infer, source_map); | 156 | infer_def(infer, source_map); |
159 | } | 157 | } |
160 | 158 | ||
161 | acc.truncate(acc.trim_end().len()); | 159 | buf.truncate(buf.trim_end().len()); |
162 | acc | 160 | buf |
163 | } | 161 | } |
164 | 162 | ||
165 | fn visit_module( | 163 | fn visit_module( |