Turn a single-variant enum into a struct

This commit is contained in:
Oli Scherer 2023-07-26 18:39:10 +00:00
parent 10da30f540
commit 2131eee179

View File

@ -7,8 +7,6 @@
//! //!
//! The output types are defined in `rustc_session::config::ErrorOutputType`. //! The output types are defined in `rustc_session::config::ErrorOutputType`.
use Destination::*;
use rustc_span::source_map::SourceMap; use rustc_span::source_map::SourceMap;
use rustc_span::{FileLines, SourceFile, Span}; use rustc_span::{FileLines, SourceFile, Span};
@ -675,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(Raw(dst), fallback_bundle) Self::create(Destination(dst), fallback_bundle)
} }
fn maybe_anonymized(&self, line_num: usize) -> Cow<'static, str> { fn maybe_anonymized(&self, line_num: usize) -> Cow<'static, str> {
@ -2603,9 +2601,7 @@ fn emit_to_destination(
Ok(()) Ok(())
} }
pub enum Destination { pub struct Destination(pub(crate) Box<(dyn WriteColor + Send)>);
Raw(Box<(dyn WriteColor + Send)>),
}
struct Buffy { struct Buffy {
buffer_writer: BufferWriter, buffer_writer: BufferWriter,
@ -2648,24 +2644,20 @@ impl Destination {
// 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) {
Raw(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();
Raw(Box::new(Buffy { buffer_writer, buffer })) Destination(Box::new(Buffy { buffer_writer, buffer }))
} }
} }
fn writable(&mut self) -> &mut dyn WriteColor { fn writable(&mut self) -> &mut dyn WriteColor {
match *self { &mut self.0
Destination::Raw(ref mut t) => t,
}
} }
fn supports_color(&self) -> bool { fn supports_color(&self) -> bool {
match *self { self.0.supports_color()
Self::Raw(ref writer) => writer.supports_color(),
}
} }
} }