diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-07-25 13:25:38 +0000 | 
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-07-31 09:34:30 +0000 | 
| commit | 0e7ec9683dae0a0bc66797b1351059ed642f4e2d (patch) | |
| tree | 5c670cce44d13c300f1bdfe5b5de0c0729a32b5c /compiler/rustc_errors/src | |
| parent | 29de70da1be1c71b89b006f9955fedc70e084067 (diff) | |
| download | rust-0e7ec9683dae0a0bc66797b1351059ed642f4e2d.tar.gz rust-0e7ec9683dae0a0bc66797b1351059ed642f4e2d.zip | |
Use builder pattern instead of lots of arguments for `EmitterWriter::new`
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 47 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/json.rs | 18 | 
2 files changed, 13 insertions, 52 deletions
| diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 70ca972ddb4..41fb1cafe25 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -62,30 +62,11 @@ impl HumanReadableErrorType { pub fn new_emitter( self, dst: Box<dyn Write + Send>, - source_map: Option<Lrc<SourceMap>>, - bundle: Option<Lrc<FluentBundle>>, fallback_bundle: LazyFallbackBundle, - teach: bool, - diagnostic_width: Option<usize>, - macro_backtrace: bool, - track_diagnostics: bool, - terminal_url: TerminalUrl, ) -> EmitterWriter { let (short, color_config) = self.unzip(); let color = color_config.suggests_using_colors(); - EmitterWriter::new( - dst, - source_map, - bundle, - fallback_bundle, - short, - teach, - color, - diagnostic_width, - macro_backtrace, - track_diagnostics, - terminal_url, - ) + EmitterWriter::new(dst, fallback_bundle, color).short_message(short) } } @@ -668,6 +649,10 @@ pub struct FileWithAnnotatedLines { impl EmitterWriter { pub fn stderr(color_config: ColorConfig, fallback_bundle: LazyFallbackBundle) -> EmitterWriter { let dst = Destination::from_stderr(color_config); + Self::create(dst, fallback_bundle) + } + + fn create(dst: Destination, fallback_bundle: LazyFallbackBundle) -> EmitterWriter { EmitterWriter { dst, sm: None, @@ -685,30 +670,10 @@ impl EmitterWriter { pub fn new( dst: Box<dyn Write + Send>, - source_map: Option<Lrc<SourceMap>>, - fluent_bundle: Option<Lrc<FluentBundle>>, fallback_bundle: LazyFallbackBundle, - short_message: bool, - teach: bool, colored: bool, - diagnostic_width: Option<usize>, - macro_backtrace: bool, - track_diagnostics: bool, - terminal_url: TerminalUrl, ) -> EmitterWriter { - EmitterWriter { - dst: Raw(dst, colored), - sm: source_map, - fluent_bundle, - fallback_bundle, - short_message, - teach, - ui_testing: false, - diagnostic_width, - macro_backtrace, - track_diagnostics, - terminal_url, - } + Self::create(Raw(dst, colored), fallback_bundle) } fn maybe_anonymized(&self, line_num: usize) -> Cow<'static, str> { diff --git a/compiler/rustc_errors/src/json.rs b/compiler/rustc_errors/src/json.rs index 55f7c485024..e199244b1e4 100644 --- a/compiler/rustc_errors/src/json.rs +++ b/compiler/rustc_errors/src/json.rs @@ -359,17 +359,13 @@ impl Diagnostic { let buf = BufWriter::default(); let output = buf.clone(); je.json_rendered - .new_emitter( - Box::new(buf), - Some(je.sm.clone()), - je.fluent_bundle.clone(), - je.fallback_bundle.clone(), - false, - je.diagnostic_width, - je.macro_backtrace, - je.track_diagnostics, - je.terminal_url, - ) + .new_emitter(Box::new(buf), je.fallback_bundle.clone()) + .sm(Some(je.sm.clone())) + .fluent_bundle(je.fluent_bundle.clone()) + .diagnostic_width(je.diagnostic_width) + .macro_backtrace(je.macro_backtrace) + .track_diagnostics(je.track_diagnostics) + .terminal_url(je.terminal_url) .ui_testing(je.ui_testing) .emit_diagnostic(diag); let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap(); | 
