Skip to content

Commit 0e7ec96

Browse files
committed
Use builder pattern instead of lots of arguments for EmitterWriter::new
1 parent 29de70d commit 0e7ec96

File tree

6 files changed

+24
-115
lines changed

6 files changed

+24
-115
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,11 @@ impl HumanReadableErrorType {
6262
pub fn new_emitter(
6363
self,
6464
dst: Box<dyn Write + Send>,
65-
source_map: Option<Lrc<SourceMap>>,
66-
bundle: Option<Lrc<FluentBundle>>,
6765
fallback_bundle: LazyFallbackBundle,
68-
teach: bool,
69-
diagnostic_width: Option<usize>,
70-
macro_backtrace: bool,
71-
track_diagnostics: bool,
72-
terminal_url: TerminalUrl,
7366
) -> EmitterWriter {
7467
let (short, color_config) = self.unzip();
7568
let color = color_config.suggests_using_colors();
76-
EmitterWriter::new(
77-
dst,
78-
source_map,
79-
bundle,
80-
fallback_bundle,
81-
short,
82-
teach,
83-
color,
84-
diagnostic_width,
85-
macro_backtrace,
86-
track_diagnostics,
87-
terminal_url,
88-
)
69+
EmitterWriter::new(dst, fallback_bundle, color).short_message(short)
8970
}
9071
}
9172

@@ -668,6 +649,10 @@ pub struct FileWithAnnotatedLines {
668649
impl EmitterWriter {
669650
pub fn stderr(color_config: ColorConfig, fallback_bundle: LazyFallbackBundle) -> EmitterWriter {
670651
let dst = Destination::from_stderr(color_config);
652+
Self::create(dst, fallback_bundle)
653+
}
654+
655+
fn create(dst: Destination, fallback_bundle: LazyFallbackBundle) -> EmitterWriter {
671656
EmitterWriter {
672657
dst,
673658
sm: None,
@@ -685,30 +670,10 @@ impl EmitterWriter {
685670

686671
pub fn new(
687672
dst: Box<dyn Write + Send>,
688-
source_map: Option<Lrc<SourceMap>>,
689-
fluent_bundle: Option<Lrc<FluentBundle>>,
690673
fallback_bundle: LazyFallbackBundle,
691-
short_message: bool,
692-
teach: bool,
693674
colored: bool,
694-
diagnostic_width: Option<usize>,
695-
macro_backtrace: bool,
696-
track_diagnostics: bool,
697-
terminal_url: TerminalUrl,
698675
) -> EmitterWriter {
699-
EmitterWriter {
700-
dst: Raw(dst, colored),
701-
sm: source_map,
702-
fluent_bundle,
703-
fallback_bundle,
704-
short_message,
705-
teach,
706-
ui_testing: false,
707-
diagnostic_width,
708-
macro_backtrace,
709-
track_diagnostics,
710-
terminal_url,
711-
}
676+
Self::create(Raw(dst, colored), fallback_bundle)
712677
}
713678

714679
fn maybe_anonymized(&self, line_num: usize) -> Cow<'static, str> {

compiler/rustc_errors/src/json.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -359,17 +359,13 @@ impl Diagnostic {
359359
let buf = BufWriter::default();
360360
let output = buf.clone();
361361
je.json_rendered
362-
.new_emitter(
363-
Box::new(buf),
364-
Some(je.sm.clone()),
365-
je.fluent_bundle.clone(),
366-
je.fallback_bundle.clone(),
367-
false,
368-
je.diagnostic_width,
369-
je.macro_backtrace,
370-
je.track_diagnostics,
371-
je.terminal_url,
372-
)
362+
.new_emitter(Box::new(buf), je.fallback_bundle.clone())
363+
.sm(Some(je.sm.clone()))
364+
.fluent_bundle(je.fluent_bundle.clone())
365+
.diagnostic_width(je.diagnostic_width)
366+
.macro_backtrace(je.macro_backtrace)
367+
.track_diagnostics(je.track_diagnostics)
368+
.terminal_url(je.terminal_url)
373369
.ui_testing(je.ui_testing)
374370
.emit_diagnostic(diag);
375371
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();

compiler/rustc_expand/src/tests.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::{BytePos, Span};
88

99
use rustc_data_structures::sync::Lrc;
1010
use rustc_errors::emitter::EmitterWriter;
11-
use rustc_errors::{Handler, MultiSpan, PResult, TerminalUrl};
11+
use rustc_errors::{Handler, MultiSpan, PResult};
1212

1313
use std::io;
1414
use std::io::prelude::*;
@@ -29,19 +29,10 @@ fn create_test_handler() -> (Handler, Lrc<SourceMap>, Arc<Mutex<Vec<u8>>>) {
2929
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
3030
false,
3131
);
32-
let emitter = EmitterWriter::new(
33-
Box::new(Shared { data: output.clone() }),
34-
Some(source_map.clone()),
35-
None,
36-
fallback_bundle,
37-
false,
38-
false,
39-
false,
40-
Some(140),
41-
false,
42-
false,
43-
TerminalUrl::No,
44-
);
32+
let emitter =
33+
EmitterWriter::new(Box::new(Shared { data: output.clone() }), fallback_bundle, false)
34+
.sm(Some(source_map.clone()))
35+
.diagnostic_width(Some(140));
4536
let handler = Handler::with_emitter(Box::new(emitter));
4637
(handler, source_map, output)
4738
}

src/librustdoc/doctest.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +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::{ColorConfig, ErrorGuaranteed, FatalError, TerminalUrl};
4+
use rustc_errors::{ColorConfig, ErrorGuaranteed, FatalError};
55
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
66
use rustc_hir::{self as hir, intravisit, CRATE_HIR_ID};
77
use rustc_interface::interface;
@@ -562,19 +562,7 @@ pub(crate) fn make_test(
562562
.diagnostic_width(Some(80))
563563
.supports_color();
564564

565-
let emitter = EmitterWriter::new(
566-
Box::new(io::sink()),
567-
None,
568-
None,
569-
fallback_bundle,
570-
false,
571-
false,
572-
false,
573-
None,
574-
false,
575-
false,
576-
TerminalUrl::No,
577-
);
565+
let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle, false);
578566

579567
// FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
580568
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
@@ -750,19 +738,7 @@ fn check_if_attr_is_complete(source: &str, edition: Edition) -> bool {
750738
false,
751739
);
752740

753-
let emitter = EmitterWriter::new(
754-
Box::new(io::sink()),
755-
None,
756-
None,
757-
fallback_bundle,
758-
false,
759-
false,
760-
false,
761-
None,
762-
false,
763-
false,
764-
TerminalUrl::No,
765-
);
741+
let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle, false);
766742

767743
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
768744
let sess = ParseSess::with_span_handler(handler, sm);

src/tools/clippy/clippy_lints/src/doc.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_ast::token::CommentKind;
1616
use rustc_data_structures::fx::FxHashSet;
1717
use rustc_data_structures::sync::Lrc;
1818
use rustc_errors::emitter::EmitterWriter;
19-
use rustc_errors::{Applicability, Handler, SuggestionStyle, TerminalUrl};
19+
use rustc_errors::{Applicability, Handler, SuggestionStyle};
2020
use rustc_hir as hir;
2121
use rustc_hir::intravisit::{self, Visitor};
2222
use rustc_hir::{AnonConst, Expr};
@@ -718,16 +718,8 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
718718
rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
719719
let emitter = EmitterWriter::new(
720720
Box::new(io::sink()),
721-
None,
722-
None,
723721
fallback_bundle,
724722
false,
725-
false,
726-
false,
727-
None,
728-
false,
729-
false,
730-
TerminalUrl::No,
731723
);
732724
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
733725
let sess = ParseSess::with_span_handler(handler, sm);

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
44
use rustc_data_structures::sync::{Lrc, Send};
55
use rustc_errors::emitter::{Emitter, EmitterWriter};
66
use rustc_errors::translation::Translate;
7-
use rustc_errors::{ColorConfig, Diagnostic, Handler, Level as DiagnosticLevel, TerminalUrl};
7+
use rustc_errors::{ColorConfig, Diagnostic, Handler, Level as DiagnosticLevel};
88
use rustc_session::parse::ParseSess as RawParseSess;
99
use rustc_span::{
1010
source_map::{FilePathMapping, SourceMap},
@@ -139,18 +139,7 @@ fn default_handler(
139139
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
140140
false,
141141
);
142-
Box::new(EmitterWriter::stderr(
143-
emit_color,
144-
Some(source_map.clone()),
145-
None,
146-
fallback_bundle,
147-
false,
148-
false,
149-
None,
150-
false,
151-
false,
152-
TerminalUrl::No,
153-
))
142+
Box::new(EmitterWriter::stderr(emit_color, fallback_bundle).sm(Some(source_map.clone())))
154143
};
155144
Handler::with_emitter(Box::new(SilentOnIgnoredFilesEmitter {
156145
has_non_ignorable_parser_errors: false,

0 commit comments

Comments
 (0)