From 2b444672e10d1a019c194729b9e4800d39904459 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 25 Jul 2023 10:27:34 +0000 Subject: Use a builder instead of boolean/option arguments --- compiler/rustc_errors/src/json/tests.rs | 2 +- compiler/rustc_errors/src/lib.rs | 47 ++++++++++++++++----------------- 2 files changed, 24 insertions(+), 25 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_errors/src/json/tests.rs b/compiler/rustc_errors/src/json/tests.rs index db0dd4ffe8e..1f9a2981e02 100644 --- a/compiler/rustc_errors/src/json/tests.rs +++ b/compiler/rustc_errors/src/json/tests.rs @@ -64,7 +64,7 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) { ); let span = Span::with_root_ctxt(BytePos(span.0), BytePos(span.1)); - let handler = Handler::with_emitter(true, None, Box::new(je), None); + let handler = Handler::with_emitter(Box::new(je)); handler.span_err(span, "foo"); let bytes = output.lock().unwrap(); diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index c33e870317e..d18e01d178e 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -548,12 +548,9 @@ impl Drop for HandlerInner { impl Handler { pub fn with_tty_emitter( - can_emit_warnings: bool, sm: Option>, fallback_bundle: LazyFallbackBundle, ) -> Self { - let flags = - HandlerFlags { can_emit_warnings, treat_err_as_bug: None, ..Default::default() }; let emitter = Box::new(EmitterWriter::stderr( ColorConfig::Auto, sm, @@ -562,34 +559,36 @@ impl Handler { false, false, None, - flags.macro_backtrace, - flags.track_diagnostics, + false, + false, TerminalUrl::No, )); - Self::with_emitter_and_flags(emitter, flags, None) + Self::with_emitter(emitter) + } + pub fn disable_warnings(mut self) -> Self { + self.inner.get_mut().flags.can_emit_warnings = false; + self } - pub fn with_emitter( - can_emit_warnings: bool, - treat_err_as_bug: Option, - emitter: Box, - ice_file: Option, - ) -> Self { - Handler::with_emitter_and_flags( - emitter, - HandlerFlags { can_emit_warnings, treat_err_as_bug, ..Default::default() }, - ice_file, - ) + pub fn treat_err_as_bug(mut self, treat_err_as_bug: NonZeroUsize) -> Self { + self.inner.get_mut().flags.treat_err_as_bug = Some(treat_err_as_bug); + self } - pub fn with_emitter_and_flags( - emitter: Box, - flags: HandlerFlags, - ice_file: Option, - ) -> Self { + pub fn with_flags(mut self, flags: HandlerFlags) -> Self { + self.inner.get_mut().flags = flags; + self + } + + pub fn with_ice_file(mut self, ice_file: PathBuf) -> Self { + self.inner.get_mut().ice_file = Some(ice_file); + self + } + + pub fn with_emitter(emitter: Box) -> Self { Self { inner: Lock::new(HandlerInner { - flags, + flags: HandlerFlags { can_emit_warnings: true, ..Default::default() }, lint_err_count: 0, err_count: 0, warn_count: 0, @@ -607,7 +606,7 @@ impl Handler { check_unstable_expect_diagnostics: false, unstable_expect_diagnostics: Vec::new(), fulfilled_expectations: Default::default(), - ice_file, + ice_file: None, }), } } -- cgit 1.4.1-3-g733a5