Skip to content

Commit 29de70d

Browse files
committed
Replace the many arguments of EmitterWriter::stderr with builder methods
1 parent 3be07c1 commit 29de70d

File tree

9 files changed

+97
-98
lines changed

9 files changed

+97
-98
lines changed

Cargo.lock

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,41 @@ dependencies = [
830830
"winapi",
831831
]
832832

833+
[[package]]
834+
name = "darling"
835+
version = "0.20.3"
836+
source = "registry+https://github.com/rust-lang/crates.io-index"
837+
checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e"
838+
dependencies = [
839+
"darling_core",
840+
"darling_macro",
841+
]
842+
843+
[[package]]
844+
name = "darling_core"
845+
version = "0.20.3"
846+
source = "registry+https://github.com/rust-lang/crates.io-index"
847+
checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621"
848+
dependencies = [
849+
"fnv",
850+
"ident_case",
851+
"proc-macro2",
852+
"quote",
853+
"strsim",
854+
"syn 2.0.27",
855+
]
856+
857+
[[package]]
858+
name = "darling_macro"
859+
version = "0.20.3"
860+
source = "registry+https://github.com/rust-lang/crates.io-index"
861+
checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5"
862+
dependencies = [
863+
"darling_core",
864+
"quote",
865+
"syn 2.0.27",
866+
]
867+
833868
[[package]]
834869
name = "datafrog"
835870
version = "2.0.1"
@@ -869,6 +904,18 @@ dependencies = [
869904
"syn 1.0.109",
870905
]
871906

907+
[[package]]
908+
name = "derive_setters"
909+
version = "0.1.6"
910+
source = "registry+https://github.com/rust-lang/crates.io-index"
911+
checksum = "4e8ef033054e131169b8f0f9a7af8f5533a9436fadf3c500ed547f730f07090d"
912+
dependencies = [
913+
"darling",
914+
"proc-macro2",
915+
"quote",
916+
"syn 2.0.27",
917+
]
918+
872919
[[package]]
873920
name = "diff"
874921
version = "0.1.13"
@@ -1740,6 +1787,12 @@ dependencies = [
17401787
"syn 1.0.109",
17411788
]
17421789

1790+
[[package]]
1791+
name = "ident_case"
1792+
version = "1.0.1"
1793+
source = "registry+https://github.com/rust-lang/crates.io-index"
1794+
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
1795+
17431796
[[package]]
17441797
name = "idna"
17451798
version = "0.4.0"
@@ -3523,6 +3576,7 @@ name = "rustc_errors"
35233576
version = "0.0.0"
35243577
dependencies = [
35253578
"annotate-snippets",
3579+
"derive_setters",
35263580
"rustc_ast",
35273581
"rustc_ast_pretty",
35283582
"rustc_data_structures",

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ use rustc_data_structures::profiling::{
2727
use rustc_data_structures::sync::SeqCst;
2828
use rustc_errors::registry::{InvalidErrorCode, Registry};
2929
use rustc_errors::{markdown, ColorConfig};
30-
use rustc_errors::{
31-
DiagnosticMessage, ErrorGuaranteed, Handler, PResult, SubdiagnosticMessage, TerminalUrl,
32-
};
30+
use rustc_errors::{DiagnosticMessage, ErrorGuaranteed, Handler, PResult, SubdiagnosticMessage};
3331
use rustc_feature::find_gated_cfg;
3432
use rustc_fluent_macro::fluent_messages;
3533
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:
14051403
rustc_errors::fallback_fluent_bundle(crate::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
14061404
let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr(
14071405
rustc_errors::ColorConfig::Auto,
1408-
None,
1409-
None,
14101406
fallback_bundle,
1411-
false,
1412-
false,
1413-
None,
1414-
false,
1415-
false,
1416-
TerminalUrl::No,
14171407
));
14181408
let handler = rustc_errors::Handler::with_emitter(emitter);
14191409

compiler/rustc_errors/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ annotate-snippets = "0.9"
2525
termize = "0.1.1"
2626
serde = { version = "1.0.125", features = [ "derive" ] }
2727
serde_json = "1.0.59"
28+
derive_setters = "0.1.6"
2829

2930
[target.'cfg(windows)'.dependencies.windows]
3031
version = "0.48.0"

compiler/rustc_errors/src/emitter.rs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::{
2424
};
2525
use rustc_lint_defs::pluralize;
2626

27+
use derive_setters::Setters;
2728
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
2829
use rustc_data_structures::sync::Lrc;
2930
use rustc_error_messages::{FluentArgs, SpanLabel};
@@ -639,10 +640,13 @@ impl ColorConfig {
639640
}
640641

641642
/// Handles the writing of `HumanReadableErrorType::Default` and `HumanReadableErrorType::Short`
643+
#[derive(Setters)]
642644
pub struct EmitterWriter {
645+
#[setters(skip)]
643646
dst: Destination,
644647
sm: Option<Lrc<SourceMap>>,
645648
fluent_bundle: Option<Lrc<FluentBundle>>,
649+
#[setters(skip)]
646650
fallback_bundle: LazyFallbackBundle,
647651
short_message: bool,
648652
teach: bool,
@@ -662,31 +666,20 @@ pub struct FileWithAnnotatedLines {
662666
}
663667

664668
impl EmitterWriter {
665-
pub fn stderr(
666-
color_config: ColorConfig,
667-
source_map: Option<Lrc<SourceMap>>,
668-
fluent_bundle: Option<Lrc<FluentBundle>>,
669-
fallback_bundle: LazyFallbackBundle,
670-
short_message: bool,
671-
teach: bool,
672-
diagnostic_width: Option<usize>,
673-
macro_backtrace: bool,
674-
track_diagnostics: bool,
675-
terminal_url: TerminalUrl,
676-
) -> EmitterWriter {
669+
pub fn stderr(color_config: ColorConfig, fallback_bundle: LazyFallbackBundle) -> EmitterWriter {
677670
let dst = Destination::from_stderr(color_config);
678671
EmitterWriter {
679672
dst,
680-
sm: source_map,
681-
fluent_bundle,
673+
sm: None,
674+
fluent_bundle: None,
682675
fallback_bundle,
683-
short_message,
684-
teach,
676+
short_message: false,
677+
teach: false,
685678
ui_testing: false,
686-
diagnostic_width,
687-
macro_backtrace,
688-
track_diagnostics,
689-
terminal_url,
679+
diagnostic_width: None,
680+
macro_backtrace: false,
681+
track_diagnostics: false,
682+
terminal_url: TerminalUrl::No,
690683
}
691684
}
692685

@@ -718,11 +711,6 @@ impl EmitterWriter {
718711
}
719712
}
720713

721-
pub fn ui_testing(mut self, ui_testing: bool) -> Self {
722-
self.ui_testing = ui_testing;
723-
self
724-
}
725-
726714
fn maybe_anonymized(&self, line_num: usize) -> Cow<'static, str> {
727715
if self.ui_testing {
728716
Cow::Borrowed(ANONYMIZED_LINE_NUM)

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -556,18 +556,7 @@ impl Handler {
556556
sm: Option<Lrc<SourceMap>>,
557557
fallback_bundle: LazyFallbackBundle,
558558
) -> Self {
559-
let emitter = Box::new(EmitterWriter::stderr(
560-
ColorConfig::Auto,
561-
sm,
562-
None,
563-
fallback_bundle,
564-
false,
565-
false,
566-
None,
567-
false,
568-
false,
569-
TerminalUrl::No,
570-
));
559+
let emitter = Box::new(EmitterWriter::stderr(ColorConfig::Auto, fallback_bundle).sm(sm));
571560
Self::with_emitter(emitter)
572561
}
573562
pub fn disable_warnings(mut self) -> Self {

compiler/rustc_session/src/session.rs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,18 +1350,15 @@ fn default_emitter(
13501350
);
13511351
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
13521352
} else {
1353-
let emitter = EmitterWriter::stderr(
1354-
color_config,
1355-
Some(source_map),
1356-
bundle,
1357-
fallback_bundle,
1358-
short,
1359-
sopts.unstable_opts.teach,
1360-
sopts.diagnostic_width,
1361-
macro_backtrace,
1362-
track_diagnostics,
1363-
terminal_url,
1364-
);
1353+
let emitter = EmitterWriter::stderr(color_config, fallback_bundle)
1354+
.fluent_bundle(bundle)
1355+
.sm(Some(source_map))
1356+
.short_message(short)
1357+
.teach(sopts.unstable_opts.teach)
1358+
.diagnostic_width(sopts.diagnostic_width)
1359+
.macro_backtrace(macro_backtrace)
1360+
.track_diagnostics(track_diagnostics)
1361+
.terminal_url(terminal_url);
13651362
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
13661363
}
13671364
}
@@ -1794,18 +1791,7 @@ fn mk_emitter(output: ErrorOutputType) -> Box<dyn Emitter + sync::Send + 'static
17941791
let emitter: Box<dyn Emitter + sync::Send> = match output {
17951792
config::ErrorOutputType::HumanReadable(kind) => {
17961793
let (short, color_config) = kind.unzip();
1797-
Box::new(EmitterWriter::stderr(
1798-
color_config,
1799-
None,
1800-
None,
1801-
fallback_bundle,
1802-
short,
1803-
false,
1804-
None,
1805-
false,
1806-
false,
1807-
TerminalUrl::No,
1808-
))
1794+
Box::new(EmitterWriter::stderr(color_config, fallback_bundle).short_message(short))
18091795
}
18101796
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(JsonEmitter::basic(
18111797
pretty,

src/librustdoc/core.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,13 @@ pub(crate) fn new_handler(
136136
ErrorOutputType::HumanReadable(kind) => {
137137
let (short, color_config) = kind.unzip();
138138
Box::new(
139-
EmitterWriter::stderr(
140-
color_config,
141-
source_map.map(|sm| sm as _),
142-
None,
143-
fallback_bundle,
144-
short,
145-
unstable_opts.teach,
146-
diagnostic_width,
147-
false,
148-
unstable_opts.track_diagnostics,
149-
TerminalUrl::No,
150-
)
151-
.ui_testing(unstable_opts.ui_testing),
139+
EmitterWriter::stderr(color_config, fallback_bundle)
140+
.sm(source_map.map(|sm| sm as _))
141+
.short_message(short)
142+
.teach(unstable_opts.teach)
143+
.diagnostic_width(diagnostic_width)
144+
.track_diagnostics(unstable_opts.track_diagnostics)
145+
.ui_testing(unstable_opts.ui_testing),
152146
)
153147
}
154148
ErrorOutputType::Json { pretty, json_rendered } => {

src/librustdoc/doctest.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -558,19 +558,9 @@ pub(crate) fn make_test(
558558
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
559559
false,
560560
);
561-
supports_color = EmitterWriter::stderr(
562-
ColorConfig::Auto,
563-
None,
564-
None,
565-
fallback_bundle.clone(),
566-
false,
567-
false,
568-
Some(80),
569-
false,
570-
false,
571-
TerminalUrl::No,
572-
)
573-
.supports_color();
561+
supports_color = EmitterWriter::stderr(ColorConfig::Auto, fallback_bundle.clone())
562+
.diagnostic_width(Some(80))
563+
.supports_color();
574564

575565
let emitter = EmitterWriter::new(
576566
Box::new(io::sink()),

src/tools/tidy/src/deps.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,12 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
138138
"crossbeam-utils",
139139
"crypto-common",
140140
"cstr",
141+
"darling",
142+
"darling_core",
143+
"darling_macro",
141144
"datafrog",
142145
"derive_more",
146+
"derive_setters",
143147
"digest",
144148
"displaydoc",
145149
"dissimilar",
@@ -158,6 +162,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
158162
"fluent-bundle",
159163
"fluent-langneg",
160164
"fluent-syntax",
165+
"fnv",
161166
"fortanix-sgx-abi",
162167
"generic-array",
163168
"getopts",
@@ -171,6 +176,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
171176
"icu_provider",
172177
"icu_provider_adapters",
173178
"icu_provider_macros",
179+
"ident_case",
174180
"indexmap",
175181
"instant",
176182
"intl-memoizer",
@@ -245,6 +251,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
245251
"stable_deref_trait",
246252
"stacker",
247253
"static_assertions",
254+
"strsim",
248255
"syn",
249256
"synstructure",
250257
"tempfile",

0 commit comments

Comments
 (0)