Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emitter cleanups #121783

Merged
merged 14 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Inline and remove HumanEmitter::stderr.
Because `HumanEmitter::new` is enough, in conjunction with the (renamed)
`stderr_destination` function.
  • Loading branch information
nnethercote committed Feb 29, 2024
commit 067d7c3d00a05989bd4b7d4b5648d61748f80848
5 changes: 3 additions & 2 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use rustc_codegen_ssa::{traits::CodegenBackend, CodegenErrors, CodegenResults};
use rustc_data_structures::profiling::{
get_resident_set_size, print_time_passes_entry, TimePassesFormat,
};
use rustc_errors::emitter::stderr_destination;
use rustc_errors::registry::Registry;
use rustc_errors::{
markdown, ColorConfig, DiagCtxt, ErrCode, ErrorGuaranteed, FatalError, PResult,
Expand Down Expand Up @@ -1384,8 +1385,8 @@ fn report_ice(
) {
let fallback_bundle =
rustc_errors::fallback_fluent_bundle(crate::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
let emitter = Box::new(rustc_errors::emitter::HumanEmitter::stderr(
rustc_errors::ColorConfig::Auto,
let emitter = Box::new(rustc_errors::emitter::HumanEmitter::new(
stderr_destination(rustc_errors::ColorConfig::Auto),
fallback_bundle,
));
let dcx = rustc_errors::DiagCtxt::new(emitter);
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,6 @@ pub(crate) struct FileWithAnnotatedLines {
}

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 {
HumanEmitter {
dst: IntoDynSyncSend(dst),
Expand Down Expand Up @@ -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();
// On Windows we'll be performing global synchronization on the entire
// system for emitting rustc errors, so there's no need to buffer
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_errors/src/json/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::*;

use crate::DiagCtxt;
use rustc_span::source_map::FilePathMapping;
use rustc_span::BytePos;

use std::str;
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_session/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::Session;
use rustc_ast::node_id::NodeId;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
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::{
fallback_fluent_bundle, ColorConfig, Diag, DiagCtxt, DiagnosticMessage, EmissionGuarantee,
MultiSpan, StashKey,
Expand Down Expand Up @@ -237,8 +237,10 @@ impl ParseSess {
pub fn new(locale_resources: Vec<&'static str>, file_path_mapping: FilePathMapping) -> Self {
let fallback_bundle = fallback_fluent_bundle(locale_resources, false);
let sm = Lrc::new(SourceMap::new(file_path_mapping));
let emitter =
Box::new(HumanEmitter::stderr(ColorConfig::Auto, fallback_bundle).sm(Some(sm.clone())));
let emitter = Box::new(
HumanEmitter::new(stderr_destination(ColorConfig::Auto), fallback_bundle)
.sm(Some(sm.clone())),
);
let dcx = DiagCtxt::new(emitter);
ParseSess::with_dcx(dcx, sm)
}
Expand Down Expand Up @@ -268,7 +270,8 @@ impl ParseSess {
pub fn with_silent_emitter(fatal_note: String) -> Self {
let fallback_bundle = fallback_fluent_bundle(Vec::new(), false);
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 dcx =
DiagCtxt::new(Box::new(SilentEmitter { fatal_dcx, fatal_note })).disable_warnings();
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_data_structures::sync::{
AtomicU64, DynSend, DynSync, Lock, Lrc, MappedReadGuard, ReadGuard, RwLock,
};
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::registry::Registry;
use rustc_errors::{
Expand Down Expand Up @@ -982,7 +982,7 @@ fn default_emitter(
);
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
} else {
let emitter = HumanEmitter::stderr(color_config, fallback_bundle)
let emitter = HumanEmitter::new(stderr_destination(color_config), fallback_bundle)
.fluent_bundle(bundle)
.sm(Some(source_map))
.short_message(short)
Expand Down Expand Up @@ -1473,7 +1473,10 @@ fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
let emitter: Box<DynEmitter> = match output {
config::ErrorOutputType::HumanReadable(kind) => {
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(
pretty,
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc;
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::{codes::*, ErrorGuaranteed, TerminalUrl};
use rustc_feature::UnstableFeatures;
Expand Down Expand Up @@ -141,7 +141,7 @@ pub(crate) fn new_dcx(
ErrorOutputType::HumanReadable(kind) => {
let (short, color_config) = kind.unzip();
Box::new(
HumanEmitter::stderr(color_config, fallback_bundle)
HumanEmitter::new(stderr_destination(color_config), fallback_bundle)
.sm(source_map.map(|sm| sm as _))
.short_message(short)
.teach(unstable_opts.teach)
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rustc_ast as ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc;
use rustc_errors::emitter::stderr_destination;
use rustc_errors::{ColorConfig, ErrorGuaranteed, FatalError};
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
use rustc_hir::{self as hir, intravisit, CRATE_HIR_ID};
Expand Down Expand Up @@ -577,7 +578,8 @@ pub(crate) fn make_test(
false,
);
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);

Expand Down
7 changes: 5 additions & 2 deletions src/tools/rustfmt/src/parse/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;
use std::sync::atomic::{AtomicBool, Ordering};

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::{
ColorConfig, Diag, DiagCtxt, DiagInner, ErrorGuaranteed, Level as DiagnosticLevel,
Expand Down Expand Up @@ -152,7 +152,10 @@ fn default_dcx(
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
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 {
has_non_ignorable_parser_errors: false,
Expand Down