Skip to content

Commit 067d7c3

Browse files
committed
Inline and remove HumanEmitter::stderr.
Because `HumanEmitter::new` is enough, in conjunction with the (renamed) `stderr_destination` function.
1 parent 437325b commit 067d7c3

File tree

8 files changed

+28
-19
lines changed

8 files changed

+28
-19
lines changed

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_codegen_ssa::{traits::CodegenBackend, CodegenErrors, CodegenResults};
2121
use rustc_data_structures::profiling::{
2222
get_resident_set_size, print_time_passes_entry, TimePassesFormat,
2323
};
24+
use rustc_errors::emitter::stderr_destination;
2425
use rustc_errors::registry::Registry;
2526
use rustc_errors::{
2627
markdown, ColorConfig, DiagCtxt, ErrCode, ErrorGuaranteed, FatalError, PResult,
@@ -1384,8 +1385,8 @@ fn report_ice(
13841385
) {
13851386
let fallback_bundle =
13861387
rustc_errors::fallback_fluent_bundle(crate::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
1387-
let emitter = Box::new(rustc_errors::emitter::HumanEmitter::stderr(
1388-
rustc_errors::ColorConfig::Auto,
1388+
let emitter = Box::new(rustc_errors::emitter::HumanEmitter::new(
1389+
stderr_destination(rustc_errors::ColorConfig::Auto),
13891390
fallback_bundle,
13901391
));
13911392
let dcx = rustc_errors::DiagCtxt::new(emitter);

compiler/rustc_errors/src/emitter.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,6 @@ pub(crate) struct FileWithAnnotatedLines {
646646
}
647647

648648
impl HumanEmitter {
649-
pub fn stderr(color_config: ColorConfig, fallback_bundle: LazyFallbackBundle) -> HumanEmitter {
650-
Self::new(from_stderr(color_config), fallback_bundle)
651-
}
652-
653649
pub fn new(dst: Destination, fallback_bundle: LazyFallbackBundle) -> HumanEmitter {
654650
HumanEmitter {
655651
dst: IntoDynSyncSend(dst),
@@ -2650,7 +2646,7 @@ impl WriteColor for Buffy {
26502646
}
26512647
}
26522648

2653-
fn from_stderr(color: ColorConfig) -> Destination {
2649+
pub fn stderr_destination(color: ColorConfig) -> Destination {
26542650
let choice = color.to_color_choice();
26552651
// On Windows we'll be performing global synchronization on the entire
26562652
// system for emitting rustc errors, so there's no need to buffer

compiler/rustc_errors/src/json/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::*;
22

33
use crate::DiagCtxt;
4+
use rustc_span::source_map::FilePathMapping;
45
use rustc_span::BytePos;
56

67
use std::str;

compiler/rustc_session/src/parse.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::Session;
1313
use rustc_ast::node_id::NodeId;
1414
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
1515
use rustc_data_structures::sync::{AppendOnlyVec, Lock, Lrc};
16-
use rustc_errors::emitter::{HumanEmitter, SilentEmitter};
16+
use rustc_errors::emitter::{stderr_destination, HumanEmitter, SilentEmitter};
1717
use rustc_errors::{
1818
fallback_fluent_bundle, ColorConfig, Diag, DiagCtxt, DiagnosticMessage, EmissionGuarantee,
1919
MultiSpan, StashKey,
@@ -237,8 +237,10 @@ impl ParseSess {
237237
pub fn new(locale_resources: Vec<&'static str>, file_path_mapping: FilePathMapping) -> Self {
238238
let fallback_bundle = fallback_fluent_bundle(locale_resources, false);
239239
let sm = Lrc::new(SourceMap::new(file_path_mapping));
240-
let emitter =
241-
Box::new(HumanEmitter::stderr(ColorConfig::Auto, fallback_bundle).sm(Some(sm.clone())));
240+
let emitter = Box::new(
241+
HumanEmitter::new(stderr_destination(ColorConfig::Auto), fallback_bundle)
242+
.sm(Some(sm.clone())),
243+
);
242244
let dcx = DiagCtxt::new(emitter);
243245
ParseSess::with_dcx(dcx, sm)
244246
}
@@ -268,7 +270,8 @@ impl ParseSess {
268270
pub fn with_silent_emitter(fatal_note: String) -> Self {
269271
let fallback_bundle = fallback_fluent_bundle(Vec::new(), false);
270272
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
271-
let emitter = Box::new(HumanEmitter::stderr(ColorConfig::Auto, fallback_bundle));
273+
let emitter =
274+
Box::new(HumanEmitter::new(stderr_destination(ColorConfig::Auto), fallback_bundle));
272275
let fatal_dcx = DiagCtxt::new(emitter);
273276
let dcx =
274277
DiagCtxt::new(Box::new(SilentEmitter { fatal_dcx, fatal_note })).disable_warnings();

compiler/rustc_session/src/session.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_data_structures::sync::{
1818
AtomicU64, DynSend, DynSync, Lock, Lrc, MappedReadGuard, ReadGuard, RwLock,
1919
};
2020
use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
21-
use rustc_errors::emitter::{DynEmitter, HumanEmitter, HumanReadableErrorType};
21+
use rustc_errors::emitter::{stderr_destination, DynEmitter, HumanEmitter, HumanReadableErrorType};
2222
use rustc_errors::json::JsonEmitter;
2323
use rustc_errors::registry::Registry;
2424
use rustc_errors::{
@@ -982,7 +982,7 @@ fn default_emitter(
982982
);
983983
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
984984
} else {
985-
let emitter = HumanEmitter::stderr(color_config, fallback_bundle)
985+
let emitter = HumanEmitter::new(stderr_destination(color_config), fallback_bundle)
986986
.fluent_bundle(bundle)
987987
.sm(Some(source_map))
988988
.short_message(short)
@@ -1473,7 +1473,10 @@ fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
14731473
let emitter: Box<DynEmitter> = match output {
14741474
config::ErrorOutputType::HumanReadable(kind) => {
14751475
let (short, color_config) = kind.unzip();
1476-
Box::new(HumanEmitter::stderr(color_config, fallback_bundle).short_message(short))
1476+
Box::new(
1477+
HumanEmitter::new(stderr_destination(color_config), fallback_bundle)
1478+
.short_message(short),
1479+
)
14771480
}
14781481
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(JsonEmitter::basic(
14791482
pretty,

src/librustdoc/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
22
use rustc_data_structures::sync::Lrc;
33
use rustc_data_structures::unord::UnordSet;
4-
use rustc_errors::emitter::{DynEmitter, HumanEmitter};
4+
use rustc_errors::emitter::{stderr_destination, DynEmitter, HumanEmitter};
55
use rustc_errors::json::JsonEmitter;
66
use rustc_errors::{codes::*, ErrorGuaranteed, TerminalUrl};
77
use rustc_feature::UnstableFeatures;
@@ -141,7 +141,7 @@ pub(crate) fn new_dcx(
141141
ErrorOutputType::HumanReadable(kind) => {
142142
let (short, color_config) = kind.unzip();
143143
Box::new(
144-
HumanEmitter::stderr(color_config, fallback_bundle)
144+
HumanEmitter::new(stderr_destination(color_config), fallback_bundle)
145145
.sm(source_map.map(|sm| sm as _))
146146
.short_message(short)
147147
.teach(unstable_opts.teach)

src/librustdoc/doctest.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc_ast as ast;
22
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
33
use rustc_data_structures::sync::Lrc;
4+
use rustc_errors::emitter::stderr_destination;
45
use rustc_errors::{ColorConfig, ErrorGuaranteed, FatalError};
56
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
67
use rustc_hir::{self as hir, intravisit, CRATE_HIR_ID};
@@ -577,7 +578,8 @@ pub(crate) fn make_test(
577578
false,
578579
);
579580
supports_color =
580-
HumanEmitter::stderr(ColorConfig::Auto, fallback_bundle.clone()).supports_color();
581+
HumanEmitter::new(stderr_destination(ColorConfig::Auto), fallback_bundle.clone())
582+
.supports_color();
581583

582584
let emitter = HumanEmitter::new(Box::new(io::sink()), fallback_bundle);
583585

src/tools/rustfmt/src/parse/session.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::Path;
33
use std::sync::atomic::{AtomicBool, Ordering};
44

55
use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
6-
use rustc_errors::emitter::{DynEmitter, Emitter, HumanEmitter};
6+
use rustc_errors::emitter::{stderr_destination, DynEmitter, Emitter, HumanEmitter};
77
use rustc_errors::translation::Translate;
88
use rustc_errors::{
99
ColorConfig, Diag, DiagCtxt, DiagInner, ErrorGuaranteed, Level as DiagnosticLevel,
@@ -152,7 +152,10 @@ fn default_dcx(
152152
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
153153
false,
154154
);
155-
Box::new(HumanEmitter::stderr(emit_color, fallback_bundle).sm(Some(source_map.clone())))
155+
Box::new(
156+
HumanEmitter::new(stderr_destination(emit_color), fallback_bundle)
157+
.sm(Some(source_map.clone())),
158+
)
156159
};
157160
DiagCtxt::new(Box::new(SilentOnIgnoredFilesEmitter {
158161
has_non_ignorable_parser_errors: false,

0 commit comments

Comments
 (0)