Skip to content

Commit 2b44467

Browse files
committed
Use a builder instead of boolean/option arguments
1 parent cf9f53c commit 2b44467

File tree

12 files changed

+45
-56
lines changed

12 files changed

+45
-56
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
362362

363363
impl<B: WriteBackendMethods> CodegenContext<B> {
364364
pub fn create_diag_handler(&self) -> Handler {
365-
Handler::with_emitter(true, None, Box::new(self.diag_emitter.clone()), None)
365+
Handler::with_emitter(Box::new(self.diag_emitter.clone()))
366366
}
367367

368368
pub fn config(&self, kind: ModuleKind) -> &ModuleConfig {

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str, extra_info:
14151415
false,
14161416
TerminalUrl::No,
14171417
));
1418-
let handler = rustc_errors::Handler::with_emitter(true, None, emitter, None);
1418+
let handler = rustc_errors::Handler::with_emitter(emitter);
14191419

14201420
// a .span_bug or .bug call has already printed what
14211421
// it wants to print.

compiler/rustc_errors/src/json/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
6464
);
6565

6666
let span = Span::with_root_ctxt(BytePos(span.0), BytePos(span.1));
67-
let handler = Handler::with_emitter(true, None, Box::new(je), None);
67+
let handler = Handler::with_emitter(Box::new(je));
6868
handler.span_err(span, "foo");
6969

7070
let bytes = output.lock().unwrap();

compiler/rustc_errors/src/lib.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,9 @@ impl Drop for HandlerInner {
548548

549549
impl Handler {
550550
pub fn with_tty_emitter(
551-
can_emit_warnings: bool,
552551
sm: Option<Lrc<SourceMap>>,
553552
fallback_bundle: LazyFallbackBundle,
554553
) -> Self {
555-
let flags =
556-
HandlerFlags { can_emit_warnings, treat_err_as_bug: None, ..Default::default() };
557554
let emitter = Box::new(EmitterWriter::stderr(
558555
ColorConfig::Auto,
559556
sm,
@@ -562,34 +559,36 @@ impl Handler {
562559
false,
563560
false,
564561
None,
565-
flags.macro_backtrace,
566-
flags.track_diagnostics,
562+
false,
563+
false,
567564
TerminalUrl::No,
568565
));
569-
Self::with_emitter_and_flags(emitter, flags, None)
566+
Self::with_emitter(emitter)
567+
}
568+
pub fn disable_warnings(mut self) -> Self {
569+
self.inner.get_mut().flags.can_emit_warnings = false;
570+
self
570571
}
571572

572-
pub fn with_emitter(
573-
can_emit_warnings: bool,
574-
treat_err_as_bug: Option<NonZeroUsize>,
575-
emitter: Box<dyn Emitter + sync::Send>,
576-
ice_file: Option<PathBuf>,
577-
) -> Self {
578-
Handler::with_emitter_and_flags(
579-
emitter,
580-
HandlerFlags { can_emit_warnings, treat_err_as_bug, ..Default::default() },
581-
ice_file,
582-
)
573+
pub fn treat_err_as_bug(mut self, treat_err_as_bug: NonZeroUsize) -> Self {
574+
self.inner.get_mut().flags.treat_err_as_bug = Some(treat_err_as_bug);
575+
self
583576
}
584577

585-
pub fn with_emitter_and_flags(
586-
emitter: Box<dyn Emitter + sync::Send>,
587-
flags: HandlerFlags,
588-
ice_file: Option<PathBuf>,
589-
) -> Self {
578+
pub fn with_flags(mut self, flags: HandlerFlags) -> Self {
579+
self.inner.get_mut().flags = flags;
580+
self
581+
}
582+
583+
pub fn with_ice_file(mut self, ice_file: PathBuf) -> Self {
584+
self.inner.get_mut().ice_file = Some(ice_file);
585+
self
586+
}
587+
588+
pub fn with_emitter(emitter: Box<dyn Emitter + sync::Send>) -> Self {
590589
Self {
591590
inner: Lock::new(HandlerInner {
592-
flags,
591+
flags: HandlerFlags { can_emit_warnings: true, ..Default::default() },
593592
lint_err_count: 0,
594593
err_count: 0,
595594
warn_count: 0,
@@ -607,7 +606,7 @@ impl Handler {
607606
check_unstable_expect_diagnostics: false,
608607
unstable_expect_diagnostics: Vec::new(),
609608
fulfilled_expectations: Default::default(),
610-
ice_file,
609+
ice_file: None,
611610
}),
612611
}
613612
}

compiler/rustc_expand/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
161161
false,
162162
TerminalUrl::No,
163163
);
164-
let handler = Handler::with_emitter(true, None, Box::new(emitter), None);
164+
let handler = Handler::with_emitter(Box::new(emitter));
165165
#[allow(rustc::untranslatable_diagnostic)]
166166
handler.span_err(msp, "foo");
167167

compiler/rustc_session/src/parse.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl ParseSess {
224224
pub fn new(locale_resources: Vec<&'static str>, file_path_mapping: FilePathMapping) -> Self {
225225
let fallback_bundle = fallback_fluent_bundle(locale_resources, false);
226226
let sm = Lrc::new(SourceMap::new(file_path_mapping));
227-
let handler = Handler::with_tty_emitter(true, Some(sm.clone()), fallback_bundle);
227+
let handler = Handler::with_tty_emitter(Some(sm.clone()), fallback_bundle);
228228
ParseSess::with_span_handler(handler, sm)
229229
}
230230

@@ -254,13 +254,9 @@ impl ParseSess {
254254
pub fn with_silent_emitter(fatal_note: Option<String>) -> Self {
255255
let fallback_bundle = fallback_fluent_bundle(Vec::new(), false);
256256
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
257-
let fatal_handler = Handler::with_tty_emitter(false, None, fallback_bundle);
258-
let handler = Handler::with_emitter(
259-
false,
260-
None,
261-
Box::new(SilentEmitter { fatal_handler, fatal_note }),
262-
None,
263-
);
257+
let fatal_handler = Handler::with_tty_emitter(None, fallback_bundle).disable_warnings();
258+
let handler = Handler::with_emitter(Box::new(SilentEmitter { fatal_handler, fatal_note }))
259+
.disable_warnings();
264260
ParseSess::with_span_handler(handler, sm)
265261
}
266262

compiler/rustc_session/src/session.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,11 +1442,11 @@ pub fn build_session(
14421442
);
14431443
let emitter = default_emitter(&sopts, registry, source_map.clone(), bundle, fallback_bundle);
14441444

1445-
let span_diagnostic = rustc_errors::Handler::with_emitter_and_flags(
1446-
emitter,
1447-
sopts.unstable_opts.diagnostic_handler_flags(can_emit_warnings),
1448-
ice_file,
1449-
);
1445+
let mut span_diagnostic = rustc_errors::Handler::with_emitter(emitter)
1446+
.with_flags(sopts.unstable_opts.diagnostic_handler_flags(can_emit_warnings));
1447+
if let Some(ice_file) = ice_file {
1448+
span_diagnostic = span_diagnostic.with_ice_file(ice_file);
1449+
}
14501450

14511451
let self_profiler = if let SwitchWithOptPath::Enabled(ref d) = sopts.unstable_opts.self_profile
14521452
{
@@ -1737,7 +1737,7 @@ pub struct EarlyErrorHandler {
17371737
impl EarlyErrorHandler {
17381738
pub fn new(output: ErrorOutputType) -> Self {
17391739
let emitter = mk_emitter(output);
1740-
Self { handler: rustc_errors::Handler::with_emitter(true, None, emitter, None) }
1740+
Self { handler: rustc_errors::Handler::with_emitter(emitter) }
17411741
}
17421742

17431743
pub fn abort_if_errors(&self) {
@@ -1751,7 +1751,7 @@ impl EarlyErrorHandler {
17511751
self.handler.abort_if_errors();
17521752

17531753
let emitter = mk_emitter(output);
1754-
self.handler = Handler::with_emitter(true, None, emitter, None);
1754+
self.handler = Handler::with_emitter(emitter);
17551755
}
17561756

17571757
#[allow(rustc::untranslatable_diagnostic)]

src/librustdoc/core.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,8 @@ pub(crate) fn new_handler(
173173
}
174174
};
175175

176-
rustc_errors::Handler::with_emitter_and_flags(
177-
emitter,
178-
unstable_opts.diagnostic_handler_flags(true),
179-
None,
180-
)
176+
rustc_errors::Handler::with_emitter(emitter)
177+
.with_flags(unstable_opts.diagnostic_handler_flags(true))
181178
}
182179

183180
/// Parse, resolve, and typecheck the given crate.

src/librustdoc/doctest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ pub(crate) fn make_test(
587587
);
588588

589589
// FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
590-
let handler = Handler::with_emitter(false, None, Box::new(emitter), None);
590+
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
591591
let sess = ParseSess::with_span_handler(handler, sm);
592592

593593
let mut found_main = false;
@@ -774,7 +774,7 @@ fn check_if_attr_is_complete(source: &str, edition: Edition) -> bool {
774774
TerminalUrl::No,
775775
);
776776

777-
let handler = Handler::with_emitter(false, None, Box::new(emitter), None);
777+
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
778778
let sess = ParseSess::with_span_handler(handler, sm);
779779
let mut parser =
780780
match maybe_new_parser_from_source_str(&sess, filename, source.to_owned()) {

src/librustdoc/passes/lint/check_code_block_syntax.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn check_rust_syntax(
4040
let emitter = BufferEmitter { buffer: Lrc::clone(&buffer), fallback_bundle };
4141

4242
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
43-
let handler = Handler::with_emitter(false, None, Box::new(emitter), None);
43+
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
4444
let source = dox[code_block.code].to_owned();
4545
let sess = ParseSess::with_span_handler(handler, sm);
4646

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
729729
false,
730730
TerminalUrl::No,
731731
);
732-
let handler = Handler::with_emitter(false, None, Box::new(emitter), None);
732+
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
733733
let sess = ParseSess::with_span_handler(handler, sm);
734734

735735
let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) {

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,13 @@ fn default_handler(
153153
))
154154
};
155155
Handler::with_emitter(
156-
true,
157-
None,
158156
Box::new(SilentOnIgnoredFilesEmitter {
159157
has_non_ignorable_parser_errors: false,
160158
source_map,
161159
emitter,
162160
ignore_path_set,
163161
can_reset,
164162
}),
165-
None,
166163
)
167164
}
168165

@@ -234,7 +231,7 @@ impl ParseSess {
234231
}
235232

236233
pub(crate) fn set_silent_emitter(&mut self) {
237-
self.parse_sess.span_diagnostic = Handler::with_emitter(true, None, silent_emitter(), None);
234+
self.parse_sess.span_diagnostic = Handler::with_emitter(silent_emitter());
238235
}
239236

240237
pub(crate) fn span_to_filename(&self, span: Span) -> FileName {

0 commit comments

Comments
 (0)