From 95c1c34fff6675910986c93c3fea3c03e9810f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 8 Aug 2024 14:43:27 +0000 Subject: [PATCH] review comments --- compiler/rustc_errors/src/emitter.rs | 6 ++++++ compiler/rustc_errors/src/json.rs | 4 ++-- compiler/rustc_session/src/session.rs | 4 ++-- src/librustdoc/core.rs | 2 +- src/librustdoc/doctest.rs | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 5bd3b328cb8..9f4d9263f0f 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -48,6 +48,12 @@ pub enum HumanReadableErrorType { Short, } +impl HumanReadableErrorType { + pub fn short(&self) -> bool { + *self == HumanReadableErrorType::Short + } +} + #[derive(Clone, Copy, Debug)] struct Margin { /// The available whitespace in the left that can be consumed when centering. diff --git a/compiler/rustc_errors/src/json.rs b/compiler/rustc_errors/src/json.rs index 02a0de201ed..32e59f9ab03 100644 --- a/compiler/rustc_errors/src/json.rs +++ b/compiler/rustc_errors/src/json.rs @@ -176,7 +176,7 @@ fn source_map(&self) -> Option<&Lrc> { } 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 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 { ColorConfig::Always | ColorConfig::Auto => dst = Box::new(termcolor::Ansi::new(dst)), ColorConfig::Never => {} diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index c0fa377f8ba..672dddf871e 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -951,7 +951,7 @@ fn default_emitter( }; match sopts.error_format { config::ErrorOutputType::HumanReadable(kind, color_config) => { - let short = matches!(kind, HumanReadableErrorType::Short); + let short = kind.short(); if let HumanReadableErrorType::AnnotateSnippet = kind { let emitter = AnnotateSnippetEmitter::new( @@ -1427,7 +1427,7 @@ fn mk_emitter(output: ErrorOutputType) -> Box { fallback_fluent_bundle(vec![rustc_errors::DEFAULT_LOCALE_RESOURCE], false); let emitter: Box = match output { config::ErrorOutputType::HumanReadable(kind, color_config) => { - let short = matches!(kind, HumanReadableErrorType::Short); + let short = kind.short(); Box::new( HumanEmitter::new(stderr_destination(color_config), fallback_bundle) .short_message(short), diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index ae3456e1399..08a4a3f3fb2 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -139,7 +139,7 @@ pub(crate) fn new_dcx( ); let emitter: Box = match error_format { ErrorOutputType::HumanReadable(kind, color_config) => { - let short = matches!(kind, HumanReadableErrorType::Short); + let short = kind.short(); Box::new( HumanEmitter::new(stderr_destination(color_config), fallback_bundle) .sm(source_map.map(|sm| sm as _)) diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 68044396048..08d6a5a52b2 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -423,7 +423,7 @@ fn run_test( } }); if let ErrorOutputType::HumanReadable(kind, color_config) = rustdoc_options.error_format { - let short = matches!(kind, HumanReadableErrorType::Short); + let short = kind.short(); if short { compiler.arg("--error-format").arg("short");