Get rid of the thin wrapper type that is Destination
and just write to the Writer
trait object directly
This commit is contained in:
parent
2131eee179
commit
d9deaf4b8a
@ -649,7 +649,7 @@ pub struct FileWithAnnotatedLines {
|
|||||||
|
|
||||||
impl EmitterWriter {
|
impl EmitterWriter {
|
||||||
pub fn stderr(color_config: ColorConfig, fallback_bundle: LazyFallbackBundle) -> EmitterWriter {
|
pub fn stderr(color_config: ColorConfig, fallback_bundle: LazyFallbackBundle) -> EmitterWriter {
|
||||||
let dst = Destination::from_stderr(color_config);
|
let dst = from_stderr(color_config);
|
||||||
Self::create(dst, fallback_bundle)
|
Self::create(dst, fallback_bundle)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -673,7 +673,7 @@ impl EmitterWriter {
|
|||||||
dst: Box<dyn WriteColor + Send>,
|
dst: Box<dyn WriteColor + Send>,
|
||||||
fallback_bundle: LazyFallbackBundle,
|
fallback_bundle: LazyFallbackBundle,
|
||||||
) -> EmitterWriter {
|
) -> EmitterWriter {
|
||||||
Self::create(Destination(dst), fallback_bundle)
|
Self::create(dst, fallback_bundle)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_anonymized(&self, line_num: usize) -> Cow<'static, str> {
|
fn maybe_anonymized(&self, line_num: usize) -> Cow<'static, str> {
|
||||||
@ -2156,11 +2156,10 @@ impl EmitterWriter {
|
|||||||
Err(e) => panic!("failed to emit error: {e}"),
|
Err(e) => panic!("failed to emit error: {e}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
let dst = self.dst.writable();
|
match writeln!(self.dst) {
|
||||||
match writeln!(dst) {
|
|
||||||
Err(e) => panic!("failed to emit error: {e}"),
|
Err(e) => panic!("failed to emit error: {e}"),
|
||||||
_ => {
|
_ => {
|
||||||
if let Err(e) = dst.flush() {
|
if let Err(e) = self.dst.flush() {
|
||||||
panic!("failed to emit error: {e}")
|
panic!("failed to emit error: {e}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2571,8 +2570,6 @@ fn emit_to_destination(
|
|||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
use crate::lock;
|
use crate::lock;
|
||||||
|
|
||||||
let dst = dst.writable();
|
|
||||||
|
|
||||||
// In order to prevent error message interleaving, where multiple error lines get intermixed
|
// In order to prevent error message interleaving, where multiple error lines get intermixed
|
||||||
// when multiple compiler processes error simultaneously, we emit errors with additional
|
// when multiple compiler processes error simultaneously, we emit errors with additional
|
||||||
// steps.
|
// steps.
|
||||||
@ -2601,7 +2598,7 @@ fn emit_to_destination(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Destination(pub(crate) Box<(dyn WriteColor + Send)>);
|
pub type Destination = Box<(dyn WriteColor + Send)>;
|
||||||
|
|
||||||
struct Buffy {
|
struct Buffy {
|
||||||
buffer_writer: BufferWriter,
|
buffer_writer: BufferWriter,
|
||||||
@ -2634,30 +2631,20 @@ impl WriteColor for Buffy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Destination {
|
fn from_stderr(color: ColorConfig) -> Destination {
|
||||||
fn from_stderr(color: ColorConfig) -> Destination {
|
let choice = color.to_color_choice();
|
||||||
let choice = color.to_color_choice();
|
// On Windows we'll be performing global synchronization on the entire
|
||||||
// On Windows we'll be performing global synchronization on the entire
|
// system for emitting rustc errors, so there's no need to buffer
|
||||||
// system for emitting rustc errors, so there's no need to buffer
|
// anything.
|
||||||
// anything.
|
//
|
||||||
//
|
// On non-Windows we rely on the atomicity of `write` to ensure errors
|
||||||
// On non-Windows we rely on the atomicity of `write` to ensure errors
|
// don't get all jumbled up.
|
||||||
// don't get all jumbled up.
|
if cfg!(windows) {
|
||||||
if cfg!(windows) {
|
Box::new(StandardStream::stderr(choice))
|
||||||
Destination(Box::new(StandardStream::stderr(choice)))
|
} else {
|
||||||
} else {
|
let buffer_writer = BufferWriter::stderr(choice);
|
||||||
let buffer_writer = BufferWriter::stderr(choice);
|
let buffer = buffer_writer.buffer();
|
||||||
let buffer = buffer_writer.buffer();
|
Box::new(Buffy { buffer_writer, buffer })
|
||||||
Destination(Box::new(Buffy { buffer_writer, buffer }))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn writable(&mut self) -> &mut dyn WriteColor {
|
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
|
|
||||||
fn supports_color(&self) -> bool {
|
|
||||||
self.0.supports_color()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user