Skip to content

Commit 9d9e7c9

Browse files
committed
rustc_codegen_spirv/test: unbreak after termcolor-related changes.
1 parent 8858d5f commit 9d9e7c9

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rustc_codegen_spirv/Cargo.toml

-7
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ spirt = "0.3.0"
6262
lazy_static = "1.4.0"
6363
itertools = "0.10.5"
6464

65-
# `termcolor` is needed because we cannot construct an Emitter after it was added in
66-
# https://github.com/rust-lang/rust/pull/114104. This can be removed when
67-
# https://github.com/rust-lang/rust/pull/115393 lands.
68-
# We need to construct an emitter as yet another workaround,
69-
# see https://github.com/rust-lang/rust/pull/102992.
70-
termcolor = "1.2"
71-
7265
[dev-dependencies]
7366
pipe = "0.4"
7467
pretty_assertions = "1.0"

crates/rustc_codegen_spirv/src/linker/test.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ use rustc_session::CompilerIO;
66
use rustc_span::FileName;
77
use std::io::Write;
88
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;
916
use termcolor::{ColorSpec, WriteColor};
1017

1118
// https://github.com/colin-kiegel/rust-pretty-assertions/issues/24
@@ -81,9 +88,8 @@ fn link_with_linker_opts(
8188
struct BufWriter(Arc<Mutex<Vec<u8>>>);
8289

8390
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()
8793
}
8894
}
8995

@@ -190,7 +196,13 @@ fn link_with_linker_opts(
190196
})
191197
})
192198
.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+
})
194206
.map_err(PrettyString)
195207
}
196208

0 commit comments

Comments
 (0)