diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-02-29 16:03:59 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-02-29 17:50:26 +1100 |
| commit | 9ff4487999ccd02065ec56fdc8cee665feae9680 (patch) | |
| tree | 37a6eb3f8c29c6e3979ef764eb8baa7336f83db3 /compiler/rustc_errors/src | |
| parent | 2999d8dc72e9ed9e895d6a9e2d3d34f1cd4370ba (diff) | |
| download | rust-9ff4487999ccd02065ec56fdc8cee665feae9680.tar.gz rust-9ff4487999ccd02065ec56fdc8cee665feae9680.zip | |
Make `JsonEmitter` more like `HumanEmitter`.
Use `derive(Setters)` to derive setters, and then change `JsonEmitter::new` to only have the arguments that are always used.
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/json.rs | 48 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/json/tests.rs | 8 |
3 files changed, 21 insertions, 38 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 87e4a5ead4d..5637c05d04c 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -21,12 +21,11 @@ use crate::{ FluentBundle, LazyFallbackBundle, Level, MultiSpan, Subdiag, SubstitutionHighlight, SuggestionStyle, TerminalUrl, }; -use rustc_lint_defs::pluralize; - use derive_setters::Setters; use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; use rustc_data_structures::sync::{DynSend, IntoDynSyncSend, Lrc}; use rustc_error_messages::{FluentArgs, SpanLabel}; +use rustc_lint_defs::pluralize; use rustc_span::hygiene::{ExpnKind, MacroKind}; use std::borrow::Cow; use std::cmp::{max, min, Reverse}; diff --git a/compiler/rustc_errors/src/json.rs b/compiler/rustc_errors/src/json.rs index e99a70c393e..3166768e9e2 100644 --- a/compiler/rustc_errors/src/json.rs +++ b/compiler/rustc_errors/src/json.rs @@ -9,9 +9,6 @@ // FIXME: spec the JSON output properly. -use rustc_span::source_map::SourceMap; -use termcolor::{ColorSpec, WriteColor}; - use crate::emitter::{ should_show_source_code, ColorConfig, Destination, Emitter, HumanEmitter, HumanReadableErrorType, @@ -22,32 +19,39 @@ use crate::{ diagnostic::IsLint, CodeSuggestion, FluentBundle, LazyFallbackBundle, MultiSpan, SpanLabel, Subdiag, TerminalUrl, }; -use rustc_lint_defs::Applicability; - +use derive_setters::Setters; use rustc_data_structures::sync::{IntoDynSyncSend, Lrc}; use rustc_error_messages::FluentArgs; +use rustc_lint_defs::Applicability; use rustc_span::hygiene::ExpnData; +use rustc_span::source_map::SourceMap; use rustc_span::Span; +use serde::Serialize; use std::error::Report; use std::io::{self, Write}; use std::path::Path; use std::sync::{Arc, Mutex}; use std::vec; - -use serde::Serialize; +use termcolor::{ColorSpec, WriteColor}; #[cfg(test)] mod tests; +#[derive(Setters)] pub struct JsonEmitter { + #[setters(skip)] dst: IntoDynSyncSend<Box<dyn Write + Send>>, registry: Option<Registry>, + #[setters(skip)] sm: Lrc<SourceMap>, fluent_bundle: Option<Lrc<FluentBundle>>, + #[setters(skip)] fallback_bundle: LazyFallbackBundle, + #[setters(skip)] pretty: bool, ui_testing: bool, ignored_directories_in_source_blocks: Vec<String>, + #[setters(skip)] json_rendered: HumanReadableErrorType, diagnostic_width: Option<usize>, macro_backtrace: bool, @@ -58,42 +62,28 @@ pub struct JsonEmitter { impl JsonEmitter { pub fn new( dst: Box<dyn Write + Send>, - registry: Option<Registry>, - source_map: Lrc<SourceMap>, - fluent_bundle: Option<Lrc<FluentBundle>>, + sm: Lrc<SourceMap>, fallback_bundle: LazyFallbackBundle, pretty: bool, json_rendered: HumanReadableErrorType, - diagnostic_width: Option<usize>, - macro_backtrace: bool, - track_diagnostics: bool, - terminal_url: TerminalUrl, ) -> JsonEmitter { JsonEmitter { dst: IntoDynSyncSend(dst), - registry, - sm: source_map, - fluent_bundle, + registry: None, + sm, + fluent_bundle: None, fallback_bundle, pretty, ui_testing: false, ignored_directories_in_source_blocks: Vec::new(), json_rendered, - diagnostic_width, - macro_backtrace, - track_diagnostics, - terminal_url, + diagnostic_width: None, + macro_backtrace: false, + track_diagnostics: false, + terminal_url: TerminalUrl::No, } } - pub fn ui_testing(self, ui_testing: bool) -> Self { - Self { ui_testing, ..self } - } - - pub fn ignored_directories_in_source_blocks(self, value: Vec<String>) -> Self { - Self { ignored_directories_in_source_blocks: value, ..self } - } - fn emit(&mut self, val: EmitTyped<'_>) -> io::Result<()> { if self.pretty { serde_json::to_writer_pretty(&mut *self.dst, &val)? diff --git a/compiler/rustc_errors/src/json/tests.rs b/compiler/rustc_errors/src/json/tests.rs index fc9948cb2fc..80b4d2bf75c 100644 --- a/compiler/rustc_errors/src/json/tests.rs +++ b/compiler/rustc_errors/src/json/tests.rs @@ -48,16 +48,10 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) { let output = Arc::new(Mutex::new(Vec::new())); let je = JsonEmitter::new( Box::new(Shared { data: output.clone() }), - None, sm, - None, fallback_bundle, - true, + true, // pretty HumanReadableErrorType::Short(ColorConfig::Never), - None, - false, - false, - TerminalUrl::No, ); let span = Span::with_root_ctxt(BytePos(span.0), BytePos(span.1)); |
