@@ -7,7 +7,6 @@ mod traits;
77mod method_resolution;
88mod macros;
99
10- use std:: fmt:: Write ;
1110use std:: sync:: Arc ;
1211
1312use hir_def:: {
@@ -26,6 +25,7 @@ use ra_syntax::{
2625 algo,
2726 ast:: { self , AstNode } ,
2827} ;
28+ use stdx:: format_to;
2929
3030use crate :: { db:: HirDatabase , display:: HirDisplay , test_db:: TestDB , InferenceResult } ;
3131
@@ -63,7 +63,7 @@ fn infer(ra_fixture: &str) -> String {
6363fn infer_with_mismatches ( content : & str , include_mismatches : bool ) -> String {
6464 let ( db, file_id) = TestDB :: with_single_file ( content) ;
6565
66- let mut acc = String :: new ( ) ;
66+ let mut buf = String :: new ( ) ;
6767
6868 let mut infer_def = |inference_result : Arc < InferenceResult > ,
6969 body_source_map : Arc < BodySourceMap > | {
@@ -106,15 +106,14 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
106106 ( src_ptr. value . range ( ) , node. text ( ) . to_string ( ) . replace ( "\n " , " " ) )
107107 } ;
108108 let macro_prefix = if src_ptr. file_id != file_id. into ( ) { "!" } else { "" } ;
109- writeln ! (
110- acc ,
111- "{}{} '{}': {}" ,
109+ format_to ! (
110+ buf ,
111+ "{}{} '{}': {}\n " ,
112112 macro_prefix,
113113 range,
114114 ellipsize( text, 15 ) ,
115115 ty. display( & db)
116- )
117- . unwrap ( ) ;
116+ ) ;
118117 }
119118 if include_mismatches {
120119 mismatches. sort_by_key ( |( src_ptr, _) | {
@@ -123,15 +122,14 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
123122 for ( src_ptr, mismatch) in & mismatches {
124123 let range = src_ptr. value . range ( ) ;
125124 let macro_prefix = if src_ptr. file_id != file_id. into ( ) { "!" } else { "" } ;
126- writeln ! (
127- acc ,
128- "{}{}: expected {}, got {}" ,
125+ format_to ! (
126+ buf ,
127+ "{}{}: expected {}, got {}\n " ,
129128 macro_prefix,
130129 range,
131130 mismatch. expected. display( & db) ,
132131 mismatch. actual. display( & db) ,
133- )
134- . unwrap ( ) ;
132+ ) ;
135133 }
136134 }
137135 } ;
@@ -158,8 +156,8 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
158156 infer_def ( infer, source_map) ;
159157 }
160158
161- acc . truncate ( acc . trim_end ( ) . len ( ) ) ;
162- acc
159+ buf . truncate ( buf . trim_end ( ) . len ( ) ) ;
160+ buf
163161}
164162
165163fn visit_module (
0 commit comments