review comments

This commit is contained in:
Esteban Küber 2024-08-08 14:43:27 +00:00
parent ae696f847d
commit 95c1c34fff
5 changed files with 12 additions and 6 deletions

View File

@ -48,6 +48,12 @@ pub enum HumanReadableErrorType {
Short, Short,
} }
impl HumanReadableErrorType {
pub fn short(&self) -> bool {
*self == HumanReadableErrorType::Short
}
}
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
struct Margin { struct Margin {
/// The available whitespace in the left that can be consumed when centering. /// The available whitespace in the left that can be consumed when centering.

View File

@ -176,7 +176,7 @@ fn source_map(&self) -> Option<&Lrc<SourceMap>> {
} }
fn should_show_explain(&self) -> bool { fn should_show_explain(&self) -> bool {
!matches!(self.json_rendered, HumanReadableErrorType::Short) !self.json_rendered.short()
} }
} }
@ -356,7 +356,7 @@ fn reset(&mut self) -> io::Result<()> {
let buf = BufWriter::default(); let buf = BufWriter::default();
let mut dst: Destination = Box::new(buf.clone()); let mut dst: Destination = Box::new(buf.clone());
let short = matches!(je.json_rendered, HumanReadableErrorType::Short); let short = je.json_rendered.short();
match je.color_config { match je.color_config {
ColorConfig::Always | ColorConfig::Auto => dst = Box::new(termcolor::Ansi::new(dst)), ColorConfig::Always | ColorConfig::Auto => dst = Box::new(termcolor::Ansi::new(dst)),
ColorConfig::Never => {} ColorConfig::Never => {}

View File

@ -951,7 +951,7 @@ fn default_emitter(
}; };
match sopts.error_format { match sopts.error_format {
config::ErrorOutputType::HumanReadable(kind, color_config) => { config::ErrorOutputType::HumanReadable(kind, color_config) => {
let short = matches!(kind, HumanReadableErrorType::Short); let short = kind.short();
if let HumanReadableErrorType::AnnotateSnippet = kind { if let HumanReadableErrorType::AnnotateSnippet = kind {
let emitter = AnnotateSnippetEmitter::new( let emitter = AnnotateSnippetEmitter::new(
@ -1427,7 +1427,7 @@ fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
fallback_fluent_bundle(vec![rustc_errors::DEFAULT_LOCALE_RESOURCE], false); fallback_fluent_bundle(vec![rustc_errors::DEFAULT_LOCALE_RESOURCE], false);
let emitter: Box<DynEmitter> = match output { let emitter: Box<DynEmitter> = match output {
config::ErrorOutputType::HumanReadable(kind, color_config) => { config::ErrorOutputType::HumanReadable(kind, color_config) => {
let short = matches!(kind, HumanReadableErrorType::Short); let short = kind.short();
Box::new( Box::new(
HumanEmitter::new(stderr_destination(color_config), fallback_bundle) HumanEmitter::new(stderr_destination(color_config), fallback_bundle)
.short_message(short), .short_message(short),

View File

@ -139,7 +139,7 @@ pub(crate) fn new_dcx(
); );
let emitter: Box<DynEmitter> = match error_format { let emitter: Box<DynEmitter> = match error_format {
ErrorOutputType::HumanReadable(kind, color_config) => { ErrorOutputType::HumanReadable(kind, color_config) => {
let short = matches!(kind, HumanReadableErrorType::Short); let short = kind.short();
Box::new( Box::new(
HumanEmitter::new(stderr_destination(color_config), fallback_bundle) HumanEmitter::new(stderr_destination(color_config), fallback_bundle)
.sm(source_map.map(|sm| sm as _)) .sm(source_map.map(|sm| sm as _))

View File

@ -423,7 +423,7 @@ fn run_test(
} }
}); });
if let ErrorOutputType::HumanReadable(kind, color_config) = rustdoc_options.error_format { if let ErrorOutputType::HumanReadable(kind, color_config) = rustdoc_options.error_format {
let short = matches!(kind, HumanReadableErrorType::Short); let short = kind.short();
if short { if short {
compiler.arg("--error-format").arg("short"); compiler.arg("--error-format").arg("short");