Inline and remove HumanEmitter::stderr.

Because `HumanEmitter::new` is enough, in conjunction with the (renamed)
`stderr_destination` function.
This commit is contained in:
Nicholas Nethercote 2024-02-29 15:37:38 +11:00
parent 437325bdd4
commit 067d7c3d00
8 changed files with 28 additions and 19 deletions

View File

@ -21,6 +21,7 @@ use rustc_codegen_ssa::{traits::CodegenBackend, CodegenErrors, CodegenResults};
use rustc_data_structures::profiling::{ use rustc_data_structures::profiling::{
get_resident_set_size, print_time_passes_entry, TimePassesFormat, get_resident_set_size, print_time_passes_entry, TimePassesFormat,
}; };
use rustc_errors::emitter::stderr_destination;
use rustc_errors::registry::Registry; use rustc_errors::registry::Registry;
use rustc_errors::{ use rustc_errors::{
markdown, ColorConfig, DiagCtxt, ErrCode, ErrorGuaranteed, FatalError, PResult, markdown, ColorConfig, DiagCtxt, ErrCode, ErrorGuaranteed, FatalError, PResult,
@ -1384,8 +1385,8 @@ fn report_ice(
) { ) {
let fallback_bundle = let fallback_bundle =
rustc_errors::fallback_fluent_bundle(crate::DEFAULT_LOCALE_RESOURCES.to_vec(), false); rustc_errors::fallback_fluent_bundle(crate::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
let emitter = Box::new(rustc_errors::emitter::HumanEmitter::stderr( let emitter = Box::new(rustc_errors::emitter::HumanEmitter::new(
rustc_errors::ColorConfig::Auto, stderr_destination(rustc_errors::ColorConfig::Auto),
fallback_bundle, fallback_bundle,
)); ));
let dcx = rustc_errors::DiagCtxt::new(emitter); let dcx = rustc_errors::DiagCtxt::new(emitter);

View File

@ -646,10 +646,6 @@ pub(crate) struct FileWithAnnotatedLines {
} }
impl HumanEmitter { impl HumanEmitter {
pub fn stderr(color_config: ColorConfig, fallback_bundle: LazyFallbackBundle) -> HumanEmitter {
Self::new(from_stderr(color_config), fallback_bundle)
}
pub fn new(dst: Destination, fallback_bundle: LazyFallbackBundle) -> HumanEmitter { pub fn new(dst: Destination, fallback_bundle: LazyFallbackBundle) -> HumanEmitter {
HumanEmitter { HumanEmitter {
dst: IntoDynSyncSend(dst), dst: IntoDynSyncSend(dst),
@ -2650,7 +2646,7 @@ impl WriteColor for Buffy {
} }
} }
fn from_stderr(color: ColorConfig) -> Destination { pub fn stderr_destination(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

View File

@ -1,6 +1,7 @@
use super::*; use super::*;
use crate::DiagCtxt; use crate::DiagCtxt;
use rustc_span::source_map::FilePathMapping;
use rustc_span::BytePos; use rustc_span::BytePos;
use std::str; use std::str;

View File

@ -13,7 +13,7 @@ use crate::Session;
use rustc_ast::node_id::NodeId; use rustc_ast::node_id::NodeId;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
use rustc_data_structures::sync::{AppendOnlyVec, Lock, Lrc}; use rustc_data_structures::sync::{AppendOnlyVec, Lock, Lrc};
use rustc_errors::emitter::{HumanEmitter, SilentEmitter}; use rustc_errors::emitter::{stderr_destination, HumanEmitter, SilentEmitter};
use rustc_errors::{ use rustc_errors::{
fallback_fluent_bundle, ColorConfig, Diag, DiagCtxt, DiagnosticMessage, EmissionGuarantee, fallback_fluent_bundle, ColorConfig, Diag, DiagCtxt, DiagnosticMessage, EmissionGuarantee,
MultiSpan, StashKey, MultiSpan, StashKey,
@ -237,8 +237,10 @@ impl ParseSess {
pub fn new(locale_resources: Vec<&'static str>, file_path_mapping: FilePathMapping) -> Self { pub fn new(locale_resources: Vec<&'static str>, file_path_mapping: FilePathMapping) -> Self {
let fallback_bundle = fallback_fluent_bundle(locale_resources, false); let fallback_bundle = fallback_fluent_bundle(locale_resources, false);
let sm = Lrc::new(SourceMap::new(file_path_mapping)); let sm = Lrc::new(SourceMap::new(file_path_mapping));
let emitter = let emitter = Box::new(
Box::new(HumanEmitter::stderr(ColorConfig::Auto, fallback_bundle).sm(Some(sm.clone()))); HumanEmitter::new(stderr_destination(ColorConfig::Auto), fallback_bundle)
.sm(Some(sm.clone())),
);
let dcx = DiagCtxt::new(emitter); let dcx = DiagCtxt::new(emitter);
ParseSess::with_dcx(dcx, sm) ParseSess::with_dcx(dcx, sm)
} }
@ -268,7 +270,8 @@ impl ParseSess {
pub fn with_silent_emitter(fatal_note: String) -> Self { pub fn with_silent_emitter(fatal_note: String) -> Self {
let fallback_bundle = fallback_fluent_bundle(Vec::new(), false); let fallback_bundle = fallback_fluent_bundle(Vec::new(), false);
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let emitter = Box::new(HumanEmitter::stderr(ColorConfig::Auto, fallback_bundle)); let emitter =
Box::new(HumanEmitter::new(stderr_destination(ColorConfig::Auto), fallback_bundle));
let fatal_dcx = DiagCtxt::new(emitter); let fatal_dcx = DiagCtxt::new(emitter);
let dcx = let dcx =
DiagCtxt::new(Box::new(SilentEmitter { fatal_dcx, fatal_note })).disable_warnings(); DiagCtxt::new(Box::new(SilentEmitter { fatal_dcx, fatal_note })).disable_warnings();

View File

@ -18,7 +18,7 @@ use rustc_data_structures::sync::{
AtomicU64, DynSend, DynSync, Lock, Lrc, MappedReadGuard, ReadGuard, RwLock, AtomicU64, DynSend, DynSync, Lock, Lrc, MappedReadGuard, ReadGuard, RwLock,
}; };
use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter; use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
use rustc_errors::emitter::{DynEmitter, HumanEmitter, HumanReadableErrorType}; use rustc_errors::emitter::{stderr_destination, DynEmitter, HumanEmitter, HumanReadableErrorType};
use rustc_errors::json::JsonEmitter; use rustc_errors::json::JsonEmitter;
use rustc_errors::registry::Registry; use rustc_errors::registry::Registry;
use rustc_errors::{ use rustc_errors::{
@ -982,7 +982,7 @@ fn default_emitter(
); );
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing)) Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
} else { } else {
let emitter = HumanEmitter::stderr(color_config, fallback_bundle) let emitter = HumanEmitter::new(stderr_destination(color_config), fallback_bundle)
.fluent_bundle(bundle) .fluent_bundle(bundle)
.sm(Some(source_map)) .sm(Some(source_map))
.short_message(short) .short_message(short)
@ -1473,7 +1473,10 @@ fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
let emitter: Box<DynEmitter> = match output { let emitter: Box<DynEmitter> = match output {
config::ErrorOutputType::HumanReadable(kind) => { config::ErrorOutputType::HumanReadable(kind) => {
let (short, color_config) = kind.unzip(); let (short, color_config) = kind.unzip();
Box::new(HumanEmitter::stderr(color_config, fallback_bundle).short_message(short)) Box::new(
HumanEmitter::new(stderr_destination(color_config), fallback_bundle)
.short_message(short),
)
} }
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(JsonEmitter::basic( config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(JsonEmitter::basic(
pretty, pretty,

View File

@ -1,7 +1,7 @@
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_data_structures::unord::UnordSet; use rustc_data_structures::unord::UnordSet;
use rustc_errors::emitter::{DynEmitter, HumanEmitter}; use rustc_errors::emitter::{stderr_destination, DynEmitter, HumanEmitter};
use rustc_errors::json::JsonEmitter; use rustc_errors::json::JsonEmitter;
use rustc_errors::{codes::*, ErrorGuaranteed, TerminalUrl}; use rustc_errors::{codes::*, ErrorGuaranteed, TerminalUrl};
use rustc_feature::UnstableFeatures; use rustc_feature::UnstableFeatures;
@ -141,7 +141,7 @@ pub(crate) fn new_dcx(
ErrorOutputType::HumanReadable(kind) => { ErrorOutputType::HumanReadable(kind) => {
let (short, color_config) = kind.unzip(); let (short, color_config) = kind.unzip();
Box::new( Box::new(
HumanEmitter::stderr(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 _))
.short_message(short) .short_message(short)
.teach(unstable_opts.teach) .teach(unstable_opts.teach)

View File

@ -1,6 +1,7 @@
use rustc_ast as ast; use rustc_ast as ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_errors::emitter::stderr_destination;
use rustc_errors::{ColorConfig, ErrorGuaranteed, FatalError}; use rustc_errors::{ColorConfig, ErrorGuaranteed, FatalError};
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE}; use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
use rustc_hir::{self as hir, intravisit, CRATE_HIR_ID}; use rustc_hir::{self as hir, intravisit, CRATE_HIR_ID};
@ -577,7 +578,8 @@ pub(crate) fn make_test(
false, false,
); );
supports_color = supports_color =
HumanEmitter::stderr(ColorConfig::Auto, fallback_bundle.clone()).supports_color(); HumanEmitter::new(stderr_destination(ColorConfig::Auto), fallback_bundle.clone())
.supports_color();
let emitter = HumanEmitter::new(Box::new(io::sink()), fallback_bundle); let emitter = HumanEmitter::new(Box::new(io::sink()), fallback_bundle);

View File

@ -3,7 +3,7 @@ use std::path::Path;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use rustc_data_structures::sync::{IntoDynSyncSend, Lrc}; use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
use rustc_errors::emitter::{DynEmitter, Emitter, HumanEmitter}; use rustc_errors::emitter::{stderr_destination, DynEmitter, Emitter, HumanEmitter};
use rustc_errors::translation::Translate; use rustc_errors::translation::Translate;
use rustc_errors::{ use rustc_errors::{
ColorConfig, Diag, DiagCtxt, DiagInner, ErrorGuaranteed, Level as DiagnosticLevel, ColorConfig, Diag, DiagCtxt, DiagInner, ErrorGuaranteed, Level as DiagnosticLevel,
@ -152,7 +152,10 @@ fn default_dcx(
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
false, false,
); );
Box::new(HumanEmitter::stderr(emit_color, fallback_bundle).sm(Some(source_map.clone()))) Box::new(
HumanEmitter::new(stderr_destination(emit_color), fallback_bundle)
.sm(Some(source_map.clone())),
)
}; };
DiagCtxt::new(Box::new(SilentOnIgnoredFilesEmitter { DiagCtxt::new(Box::new(SilentOnIgnoredFilesEmitter {
has_non_ignorable_parser_errors: false, has_non_ignorable_parser_errors: false,