Replace the many arguments of EmitterWriter::stderr
with builder methods
This commit is contained in:
parent
3be07c1161
commit
29de70da1b
9 changed files with 97 additions and 98 deletions
54
Cargo.lock
54
Cargo.lock
|
@ -830,6 +830,41 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "darling"
|
||||||
|
version = "0.20.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e"
|
||||||
|
dependencies = [
|
||||||
|
"darling_core",
|
||||||
|
"darling_macro",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "darling_core"
|
||||||
|
version = "0.20.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621"
|
||||||
|
dependencies = [
|
||||||
|
"fnv",
|
||||||
|
"ident_case",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"strsim",
|
||||||
|
"syn 2.0.27",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "darling_macro"
|
||||||
|
version = "0.20.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5"
|
||||||
|
dependencies = [
|
||||||
|
"darling_core",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.27",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "datafrog"
|
name = "datafrog"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
|
@ -869,6 +904,18 @@ dependencies = [
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "derive_setters"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4e8ef033054e131169b8f0f9a7af8f5533a9436fadf3c500ed547f730f07090d"
|
||||||
|
dependencies = [
|
||||||
|
"darling",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.27",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "diff"
|
name = "diff"
|
||||||
version = "0.1.13"
|
version = "0.1.13"
|
||||||
|
@ -1740,6 +1787,12 @@ dependencies = [
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ident_case"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "idna"
|
name = "idna"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
@ -3523,6 +3576,7 @@ name = "rustc_errors"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"annotate-snippets",
|
"annotate-snippets",
|
||||||
|
"derive_setters",
|
||||||
"rustc_ast",
|
"rustc_ast",
|
||||||
"rustc_ast_pretty",
|
"rustc_ast_pretty",
|
||||||
"rustc_data_structures",
|
"rustc_data_structures",
|
||||||
|
|
|
@ -27,9 +27,7 @@ use rustc_data_structures::profiling::{
|
||||||
use rustc_data_structures::sync::SeqCst;
|
use rustc_data_structures::sync::SeqCst;
|
||||||
use rustc_errors::registry::{InvalidErrorCode, Registry};
|
use rustc_errors::registry::{InvalidErrorCode, Registry};
|
||||||
use rustc_errors::{markdown, ColorConfig};
|
use rustc_errors::{markdown, ColorConfig};
|
||||||
use rustc_errors::{
|
use rustc_errors::{DiagnosticMessage, ErrorGuaranteed, Handler, PResult, SubdiagnosticMessage};
|
||||||
DiagnosticMessage, ErrorGuaranteed, Handler, PResult, SubdiagnosticMessage, TerminalUrl,
|
|
||||||
};
|
|
||||||
use rustc_feature::find_gated_cfg;
|
use rustc_feature::find_gated_cfg;
|
||||||
use rustc_fluent_macro::fluent_messages;
|
use rustc_fluent_macro::fluent_messages;
|
||||||
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
|
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
|
||||||
|
@ -1405,15 +1403,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str, extra_info:
|
||||||
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::EmitterWriter::stderr(
|
let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr(
|
||||||
rustc_errors::ColorConfig::Auto,
|
rustc_errors::ColorConfig::Auto,
|
||||||
None,
|
|
||||||
None,
|
|
||||||
fallback_bundle,
|
fallback_bundle,
|
||||||
false,
|
|
||||||
false,
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
TerminalUrl::No,
|
|
||||||
));
|
));
|
||||||
let handler = rustc_errors::Handler::with_emitter(emitter);
|
let handler = rustc_errors::Handler::with_emitter(emitter);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ annotate-snippets = "0.9"
|
||||||
termize = "0.1.1"
|
termize = "0.1.1"
|
||||||
serde = { version = "1.0.125", features = [ "derive" ] }
|
serde = { version = "1.0.125", features = [ "derive" ] }
|
||||||
serde_json = "1.0.59"
|
serde_json = "1.0.59"
|
||||||
|
derive_setters = "0.1.6"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies.windows]
|
[target.'cfg(windows)'.dependencies.windows]
|
||||||
version = "0.48.0"
|
version = "0.48.0"
|
||||||
|
|
|
@ -24,6 +24,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use rustc_lint_defs::pluralize;
|
use rustc_lint_defs::pluralize;
|
||||||
|
|
||||||
|
use derive_setters::Setters;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_error_messages::{FluentArgs, SpanLabel};
|
use rustc_error_messages::{FluentArgs, SpanLabel};
|
||||||
|
@ -639,10 +640,13 @@ impl ColorConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the writing of `HumanReadableErrorType::Default` and `HumanReadableErrorType::Short`
|
/// Handles the writing of `HumanReadableErrorType::Default` and `HumanReadableErrorType::Short`
|
||||||
|
#[derive(Setters)]
|
||||||
pub struct EmitterWriter {
|
pub struct EmitterWriter {
|
||||||
|
#[setters(skip)]
|
||||||
dst: Destination,
|
dst: Destination,
|
||||||
sm: Option<Lrc<SourceMap>>,
|
sm: Option<Lrc<SourceMap>>,
|
||||||
fluent_bundle: Option<Lrc<FluentBundle>>,
|
fluent_bundle: Option<Lrc<FluentBundle>>,
|
||||||
|
#[setters(skip)]
|
||||||
fallback_bundle: LazyFallbackBundle,
|
fallback_bundle: LazyFallbackBundle,
|
||||||
short_message: bool,
|
short_message: bool,
|
||||||
teach: bool,
|
teach: bool,
|
||||||
|
@ -662,31 +666,20 @@ pub struct FileWithAnnotatedLines {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EmitterWriter {
|
impl EmitterWriter {
|
||||||
pub fn stderr(
|
pub fn stderr(color_config: ColorConfig, fallback_bundle: LazyFallbackBundle) -> EmitterWriter {
|
||||||
color_config: ColorConfig,
|
|
||||||
source_map: Option<Lrc<SourceMap>>,
|
|
||||||
fluent_bundle: Option<Lrc<FluentBundle>>,
|
|
||||||
fallback_bundle: LazyFallbackBundle,
|
|
||||||
short_message: bool,
|
|
||||||
teach: bool,
|
|
||||||
diagnostic_width: Option<usize>,
|
|
||||||
macro_backtrace: bool,
|
|
||||||
track_diagnostics: bool,
|
|
||||||
terminal_url: TerminalUrl,
|
|
||||||
) -> EmitterWriter {
|
|
||||||
let dst = Destination::from_stderr(color_config);
|
let dst = Destination::from_stderr(color_config);
|
||||||
EmitterWriter {
|
EmitterWriter {
|
||||||
dst,
|
dst,
|
||||||
sm: source_map,
|
sm: None,
|
||||||
fluent_bundle,
|
fluent_bundle: None,
|
||||||
fallback_bundle,
|
fallback_bundle,
|
||||||
short_message,
|
short_message: false,
|
||||||
teach,
|
teach: false,
|
||||||
ui_testing: false,
|
ui_testing: false,
|
||||||
diagnostic_width,
|
diagnostic_width: None,
|
||||||
macro_backtrace,
|
macro_backtrace: false,
|
||||||
track_diagnostics,
|
track_diagnostics: false,
|
||||||
terminal_url,
|
terminal_url: TerminalUrl::No,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -718,11 +711,6 @@ impl EmitterWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ui_testing(mut self, ui_testing: bool) -> Self {
|
|
||||||
self.ui_testing = ui_testing;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn maybe_anonymized(&self, line_num: usize) -> Cow<'static, str> {
|
fn maybe_anonymized(&self, line_num: usize) -> Cow<'static, str> {
|
||||||
if self.ui_testing {
|
if self.ui_testing {
|
||||||
Cow::Borrowed(ANONYMIZED_LINE_NUM)
|
Cow::Borrowed(ANONYMIZED_LINE_NUM)
|
||||||
|
|
|
@ -556,18 +556,7 @@ impl Handler {
|
||||||
sm: Option<Lrc<SourceMap>>,
|
sm: Option<Lrc<SourceMap>>,
|
||||||
fallback_bundle: LazyFallbackBundle,
|
fallback_bundle: LazyFallbackBundle,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let emitter = Box::new(EmitterWriter::stderr(
|
let emitter = Box::new(EmitterWriter::stderr(ColorConfig::Auto, fallback_bundle).sm(sm));
|
||||||
ColorConfig::Auto,
|
|
||||||
sm,
|
|
||||||
None,
|
|
||||||
fallback_bundle,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
TerminalUrl::No,
|
|
||||||
));
|
|
||||||
Self::with_emitter(emitter)
|
Self::with_emitter(emitter)
|
||||||
}
|
}
|
||||||
pub fn disable_warnings(mut self) -> Self {
|
pub fn disable_warnings(mut self) -> Self {
|
||||||
|
|
|
@ -1350,18 +1350,15 @@ 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 = EmitterWriter::stderr(
|
let emitter = EmitterWriter::stderr(color_config, fallback_bundle)
|
||||||
color_config,
|
.fluent_bundle(bundle)
|
||||||
Some(source_map),
|
.sm(Some(source_map))
|
||||||
bundle,
|
.short_message(short)
|
||||||
fallback_bundle,
|
.teach(sopts.unstable_opts.teach)
|
||||||
short,
|
.diagnostic_width(sopts.diagnostic_width)
|
||||||
sopts.unstable_opts.teach,
|
.macro_backtrace(macro_backtrace)
|
||||||
sopts.diagnostic_width,
|
.track_diagnostics(track_diagnostics)
|
||||||
macro_backtrace,
|
.terminal_url(terminal_url);
|
||||||
track_diagnostics,
|
|
||||||
terminal_url,
|
|
||||||
);
|
|
||||||
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
|
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1794,18 +1791,7 @@ fn mk_emitter(output: ErrorOutputType) -> Box<dyn Emitter + sync::Send + 'static
|
||||||
let emitter: Box<dyn Emitter + sync::Send> = match output {
|
let emitter: Box<dyn Emitter + sync::Send> = match output {
|
||||||
config::ErrorOutputType::HumanReadable(kind) => {
|
config::ErrorOutputType::HumanReadable(kind) => {
|
||||||
let (short, color_config) = kind.unzip();
|
let (short, color_config) = kind.unzip();
|
||||||
Box::new(EmitterWriter::stderr(
|
Box::new(EmitterWriter::stderr(color_config, fallback_bundle).short_message(short))
|
||||||
color_config,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
fallback_bundle,
|
|
||||||
short,
|
|
||||||
false,
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
TerminalUrl::No,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(JsonEmitter::basic(
|
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(JsonEmitter::basic(
|
||||||
pretty,
|
pretty,
|
||||||
|
|
|
@ -136,18 +136,12 @@ pub(crate) fn new_handler(
|
||||||
ErrorOutputType::HumanReadable(kind) => {
|
ErrorOutputType::HumanReadable(kind) => {
|
||||||
let (short, color_config) = kind.unzip();
|
let (short, color_config) = kind.unzip();
|
||||||
Box::new(
|
Box::new(
|
||||||
EmitterWriter::stderr(
|
EmitterWriter::stderr(color_config, fallback_bundle)
|
||||||
color_config,
|
.sm(source_map.map(|sm| sm as _))
|
||||||
source_map.map(|sm| sm as _),
|
.short_message(short)
|
||||||
None,
|
.teach(unstable_opts.teach)
|
||||||
fallback_bundle,
|
.diagnostic_width(diagnostic_width)
|
||||||
short,
|
.track_diagnostics(unstable_opts.track_diagnostics)
|
||||||
unstable_opts.teach,
|
|
||||||
diagnostic_width,
|
|
||||||
false,
|
|
||||||
unstable_opts.track_diagnostics,
|
|
||||||
TerminalUrl::No,
|
|
||||||
)
|
|
||||||
.ui_testing(unstable_opts.ui_testing),
|
.ui_testing(unstable_opts.ui_testing),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -558,18 +558,8 @@ pub(crate) fn make_test(
|
||||||
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
|
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
supports_color = EmitterWriter::stderr(
|
supports_color = EmitterWriter::stderr(ColorConfig::Auto, fallback_bundle.clone())
|
||||||
ColorConfig::Auto,
|
.diagnostic_width(Some(80))
|
||||||
None,
|
|
||||||
None,
|
|
||||||
fallback_bundle.clone(),
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
Some(80),
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
TerminalUrl::No,
|
|
||||||
)
|
|
||||||
.supports_color();
|
.supports_color();
|
||||||
|
|
||||||
let emitter = EmitterWriter::new(
|
let emitter = EmitterWriter::new(
|
||||||
|
|
|
@ -138,8 +138,12 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
|
||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
"crypto-common",
|
"crypto-common",
|
||||||
"cstr",
|
"cstr",
|
||||||
|
"darling",
|
||||||
|
"darling_core",
|
||||||
|
"darling_macro",
|
||||||
"datafrog",
|
"datafrog",
|
||||||
"derive_more",
|
"derive_more",
|
||||||
|
"derive_setters",
|
||||||
"digest",
|
"digest",
|
||||||
"displaydoc",
|
"displaydoc",
|
||||||
"dissimilar",
|
"dissimilar",
|
||||||
|
@ -158,6 +162,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
|
||||||
"fluent-bundle",
|
"fluent-bundle",
|
||||||
"fluent-langneg",
|
"fluent-langneg",
|
||||||
"fluent-syntax",
|
"fluent-syntax",
|
||||||
|
"fnv",
|
||||||
"fortanix-sgx-abi",
|
"fortanix-sgx-abi",
|
||||||
"generic-array",
|
"generic-array",
|
||||||
"getopts",
|
"getopts",
|
||||||
|
@ -171,6 +176,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
|
||||||
"icu_provider",
|
"icu_provider",
|
||||||
"icu_provider_adapters",
|
"icu_provider_adapters",
|
||||||
"icu_provider_macros",
|
"icu_provider_macros",
|
||||||
|
"ident_case",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"instant",
|
"instant",
|
||||||
"intl-memoizer",
|
"intl-memoizer",
|
||||||
|
@ -245,6 +251,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
|
||||||
"stable_deref_trait",
|
"stable_deref_trait",
|
||||||
"stacker",
|
"stacker",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
|
"strsim",
|
||||||
"syn",
|
"syn",
|
||||||
"synstructure",
|
"synstructure",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue