@@ -6,6 +6,13 @@ use rustc_session::CompilerIO;
6
6
use rustc_span:: FileName ;
7
7
use std:: io:: Write ;
8
8
use std:: sync:: { Arc , Mutex } ;
9
+
10
+ // `termcolor` is needed because we cannot construct an Emitter after it was added in
11
+ // https://github.com/rust-lang/rust/pull/114104. This can be removed when
12
+ // https://github.com/rust-lang/rust/pull/115393 lands.
13
+ // We need to construct an emitter as yet another workaround,
14
+ // see https://github.com/rust-lang/rust/pull/102992.
15
+ extern crate termcolor;
9
16
use termcolor:: { ColorSpec , WriteColor } ;
10
17
11
18
// https://github.com/colin-kiegel/rust-pretty-assertions/issues/24
@@ -81,9 +88,8 @@ fn link_with_linker_opts(
81
88
struct BufWriter ( Arc < Mutex < Vec < u8 > > > ) ;
82
89
83
90
impl BufWriter {
84
- fn to_string ( self ) -> String {
85
- let x = self . 0 . into_inner ( ) . expect ( "diagnostics unlocked" ) ;
86
- String :: from_utf8 ( x) . expect ( "conversion to string" )
91
+ fn unwrap_to_string ( self ) -> String {
92
+ String :: from_utf8 ( Arc :: try_unwrap ( self . 0 ) . ok ( ) . unwrap ( ) . into_inner ( ) . unwrap ( ) ) . unwrap ( )
87
93
}
88
94
}
89
95
@@ -190,7 +196,13 @@ fn link_with_linker_opts(
190
196
} )
191
197
} )
192
198
. flatten ( )
193
- . map_err ( |_e| buf. to_string ( ) )
199
+ . map_err ( |_e| {
200
+ let mut diags = output. unwrap_to_string ( ) ;
201
+ if let Some ( diags_without_trailing_newlines) = diags. strip_suffix ( "\n \n " ) {
202
+ diags. truncate ( diags_without_trailing_newlines. len ( ) ) ;
203
+ }
204
+ diags
205
+ } )
194
206
. map_err ( PrettyString )
195
207
}
196
208
0 commit comments