1
Fork 0

Replace the many arguments of EmitterWriter::stderr with builder methods

This commit is contained in:
Oli Scherer 2023-07-25 13:09:53 +00:00
parent 3be07c1161
commit 29de70da1b
9 changed files with 97 additions and 98 deletions

View file

@ -25,6 +25,7 @@ annotate-snippets = "0.9"
termize = "0.1.1"
serde = { version = "1.0.125", features = [ "derive" ] }
serde_json = "1.0.59"
derive_setters = "0.1.6"
[target.'cfg(windows)'.dependencies.windows]
version = "0.48.0"

View file

@ -24,6 +24,7 @@ use crate::{
};
use rustc_lint_defs::pluralize;
use derive_setters::Setters;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_data_structures::sync::Lrc;
use rustc_error_messages::{FluentArgs, SpanLabel};
@ -639,10 +640,13 @@ impl ColorConfig {
}
/// Handles the writing of `HumanReadableErrorType::Default` and `HumanReadableErrorType::Short`
#[derive(Setters)]
pub struct EmitterWriter {
#[setters(skip)]
dst: Destination,
sm: Option<Lrc<SourceMap>>,
fluent_bundle: Option<Lrc<FluentBundle>>,
#[setters(skip)]
fallback_bundle: LazyFallbackBundle,
short_message: bool,
teach: bool,
@ -662,31 +666,20 @@ pub struct FileWithAnnotatedLines {
}
impl EmitterWriter {
pub fn stderr(
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 {
pub fn stderr(color_config: ColorConfig, fallback_bundle: LazyFallbackBundle) -> EmitterWriter {
let dst = Destination::from_stderr(color_config);
EmitterWriter {
dst,
sm: source_map,
fluent_bundle,
sm: None,
fluent_bundle: None,
fallback_bundle,
short_message,
teach,
short_message: false,
teach: false,
ui_testing: false,
diagnostic_width,
macro_backtrace,
track_diagnostics,
terminal_url,
diagnostic_width: None,
macro_backtrace: false,
track_diagnostics: false,
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> {
if self.ui_testing {
Cow::Borrowed(ANONYMIZED_LINE_NUM)

View file

@ -556,18 +556,7 @@ impl Handler {
sm: Option<Lrc<SourceMap>>,
fallback_bundle: LazyFallbackBundle,
) -> Self {
let emitter = Box::new(EmitterWriter::stderr(
ColorConfig::Auto,
sm,
None,
fallback_bundle,
false,
false,
None,
false,
false,
TerminalUrl::No,
));
let emitter = Box::new(EmitterWriter::stderr(ColorConfig::Auto, fallback_bundle).sm(sm));
Self::with_emitter(emitter)
}
pub fn disable_warnings(mut self) -> Self {