aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs8
-rw-r--r--crates/ra_hir_ty/src/tests.rs26
2 files changed, 16 insertions, 18 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
5use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; 5use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile};
6use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; 6use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr};
7use stdx::format_to;
7 8
8pub use hir_def::diagnostics::UnresolvedModule; 9pub use hir_def::diagnostics::UnresolvedModule;
9pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; 10pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink};
@@ -37,12 +38,11 @@ pub struct MissingFields {
37 38
38impl Diagnostic for MissingFields { 39impl 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/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;
7mod method_resolution; 7mod method_resolution;
8mod macros; 8mod macros;
9 9
10use std::fmt::Write;
11use std::sync::Arc; 10use std::sync::Arc;
12 11
13use hir_def::{ 12use hir_def::{
@@ -26,6 +25,7 @@ use ra_syntax::{
26 algo, 25 algo,
27 ast::{self, AstNode}, 26 ast::{self, AstNode},
28}; 27};
28use stdx::format_to;
29 29
30use crate::{db::HirDatabase, display::HirDisplay, test_db::TestDB, InferenceResult}; 30use crate::{db::HirDatabase, display::HirDisplay, test_db::TestDB, InferenceResult};
31 31
@@ -63,7 +63,7 @@ fn infer(ra_fixture: &str) -> String {
63fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { 63fn 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
165fn visit_module( 163fn visit_module(