Use builder pattern instead of lots of arguments for EmitterWriter::new
This commit is contained in:
parent
29de70da1b
commit
0e7ec9683d
6 changed files with 24 additions and 115 deletions
|
@ -62,30 +62,11 @@ impl HumanReadableErrorType {
|
||||||
pub fn new_emitter(
|
pub fn new_emitter(
|
||||||
self,
|
self,
|
||||||
dst: Box<dyn Write + Send>,
|
dst: Box<dyn Write + Send>,
|
||||||
source_map: Option<Lrc<SourceMap>>,
|
|
||||||
bundle: Option<Lrc<FluentBundle>>,
|
|
||||||
fallback_bundle: LazyFallbackBundle,
|
fallback_bundle: LazyFallbackBundle,
|
||||||
teach: bool,
|
|
||||||
diagnostic_width: Option<usize>,
|
|
||||||
macro_backtrace: bool,
|
|
||||||
track_diagnostics: bool,
|
|
||||||
terminal_url: TerminalUrl,
|
|
||||||
) -> EmitterWriter {
|
) -> EmitterWriter {
|
||||||
let (short, color_config) = self.unzip();
|
let (short, color_config) = self.unzip();
|
||||||
let color = color_config.suggests_using_colors();
|
let color = color_config.suggests_using_colors();
|
||||||
EmitterWriter::new(
|
EmitterWriter::new(dst, fallback_bundle, color).short_message(short)
|
||||||
dst,
|
|
||||||
source_map,
|
|
||||||
bundle,
|
|
||||||
fallback_bundle,
|
|
||||||
short,
|
|
||||||
teach,
|
|
||||||
color,
|
|
||||||
diagnostic_width,
|
|
||||||
macro_backtrace,
|
|
||||||
track_diagnostics,
|
|
||||||
terminal_url,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -668,6 +649,10 @@ pub struct FileWithAnnotatedLines {
|
||||||
impl EmitterWriter {
|
impl EmitterWriter {
|
||||||
pub fn stderr(color_config: ColorConfig, fallback_bundle: LazyFallbackBundle) -> EmitterWriter {
|
pub fn stderr(color_config: ColorConfig, fallback_bundle: LazyFallbackBundle) -> EmitterWriter {
|
||||||
let dst = Destination::from_stderr(color_config);
|
let dst = Destination::from_stderr(color_config);
|
||||||
|
Self::create(dst, fallback_bundle)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create(dst: Destination, fallback_bundle: LazyFallbackBundle) -> EmitterWriter {
|
||||||
EmitterWriter {
|
EmitterWriter {
|
||||||
dst,
|
dst,
|
||||||
sm: None,
|
sm: None,
|
||||||
|
@ -685,30 +670,10 @@ impl EmitterWriter {
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(
|
||||||
dst: Box<dyn Write + Send>,
|
dst: Box<dyn Write + Send>,
|
||||||
source_map: Option<Lrc<SourceMap>>,
|
|
||||||
fluent_bundle: Option<Lrc<FluentBundle>>,
|
|
||||||
fallback_bundle: LazyFallbackBundle,
|
fallback_bundle: LazyFallbackBundle,
|
||||||
short_message: bool,
|
|
||||||
teach: bool,
|
|
||||||
colored: bool,
|
colored: bool,
|
||||||
diagnostic_width: Option<usize>,
|
|
||||||
macro_backtrace: bool,
|
|
||||||
track_diagnostics: bool,
|
|
||||||
terminal_url: TerminalUrl,
|
|
||||||
) -> EmitterWriter {
|
) -> EmitterWriter {
|
||||||
EmitterWriter {
|
Self::create(Raw(dst, colored), fallback_bundle)
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_anonymized(&self, line_num: usize) -> Cow<'static, str> {
|
fn maybe_anonymized(&self, line_num: usize) -> Cow<'static, str> {
|
||||||
|
|
|
@ -359,17 +359,13 @@ impl Diagnostic {
|
||||||
let buf = BufWriter::default();
|
let buf = BufWriter::default();
|
||||||
let output = buf.clone();
|
let output = buf.clone();
|
||||||
je.json_rendered
|
je.json_rendered
|
||||||
.new_emitter(
|
.new_emitter(Box::new(buf), je.fallback_bundle.clone())
|
||||||
Box::new(buf),
|
.sm(Some(je.sm.clone()))
|
||||||
Some(je.sm.clone()),
|
.fluent_bundle(je.fluent_bundle.clone())
|
||||||
je.fluent_bundle.clone(),
|
.diagnostic_width(je.diagnostic_width)
|
||||||
je.fallback_bundle.clone(),
|
.macro_backtrace(je.macro_backtrace)
|
||||||
false,
|
.track_diagnostics(je.track_diagnostics)
|
||||||
je.diagnostic_width,
|
.terminal_url(je.terminal_url)
|
||||||
je.macro_backtrace,
|
|
||||||
je.track_diagnostics,
|
|
||||||
je.terminal_url,
|
|
||||||
)
|
|
||||||
.ui_testing(je.ui_testing)
|
.ui_testing(je.ui_testing)
|
||||||
.emit_diagnostic(diag);
|
.emit_diagnostic(diag);
|
||||||
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
|
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
|
||||||
|
|
|
@ -8,7 +8,7 @@ use rustc_span::{BytePos, Span};
|
||||||
|
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_errors::emitter::EmitterWriter;
|
use rustc_errors::emitter::EmitterWriter;
|
||||||
use rustc_errors::{Handler, MultiSpan, PResult, TerminalUrl};
|
use rustc_errors::{Handler, MultiSpan, PResult};
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
@ -29,19 +29,10 @@ fn create_test_handler() -> (Handler, Lrc<SourceMap>, Arc<Mutex<Vec<u8>>>) {
|
||||||
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
|
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
let emitter = EmitterWriter::new(
|
let emitter =
|
||||||
Box::new(Shared { data: output.clone() }),
|
EmitterWriter::new(Box::new(Shared { data: output.clone() }), fallback_bundle, false)
|
||||||
Some(source_map.clone()),
|
.sm(Some(source_map.clone()))
|
||||||
None,
|
.diagnostic_width(Some(140));
|
||||||
fallback_bundle,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
Some(140),
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
TerminalUrl::No,
|
|
||||||
);
|
|
||||||
let handler = Handler::with_emitter(Box::new(emitter));
|
let handler = Handler::with_emitter(Box::new(emitter));
|
||||||
(handler, source_map, output)
|
(handler, source_map, output)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_errors::{ColorConfig, ErrorGuaranteed, FatalError, TerminalUrl};
|
use rustc_errors::{ColorConfig, ErrorGuaranteed, FatalError};
|
||||||
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
|
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
|
||||||
use rustc_hir::{self as hir, intravisit, CRATE_HIR_ID};
|
use rustc_hir::{self as hir, intravisit, CRATE_HIR_ID};
|
||||||
use rustc_interface::interface;
|
use rustc_interface::interface;
|
||||||
|
@ -562,19 +562,7 @@ pub(crate) fn make_test(
|
||||||
.diagnostic_width(Some(80))
|
.diagnostic_width(Some(80))
|
||||||
.supports_color();
|
.supports_color();
|
||||||
|
|
||||||
let emitter = EmitterWriter::new(
|
let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle, false);
|
||||||
Box::new(io::sink()),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
fallback_bundle,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
TerminalUrl::No,
|
|
||||||
);
|
|
||||||
|
|
||||||
// FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
|
// FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
|
||||||
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
|
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 {
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
let emitter = EmitterWriter::new(
|
let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle, false);
|
||||||
Box::new(io::sink()),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
fallback_bundle,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
TerminalUrl::No,
|
|
||||||
);
|
|
||||||
|
|
||||||
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
|
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
|
||||||
let sess = ParseSess::with_span_handler(handler, sm);
|
let sess = ParseSess::with_span_handler(handler, sm);
|
||||||
|
|
|
@ -16,7 +16,7 @@ use rustc_ast::token::CommentKind;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_errors::emitter::EmitterWriter;
|
use rustc_errors::emitter::EmitterWriter;
|
||||||
use rustc_errors::{Applicability, Handler, SuggestionStyle, TerminalUrl};
|
use rustc_errors::{Applicability, Handler, SuggestionStyle};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_hir::{AnonConst, Expr};
|
use rustc_hir::{AnonConst, Expr};
|
||||||
|
@ -718,16 +718,8 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
|
||||||
rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
|
rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
|
||||||
let emitter = EmitterWriter::new(
|
let emitter = EmitterWriter::new(
|
||||||
Box::new(io::sink()),
|
Box::new(io::sink()),
|
||||||
None,
|
|
||||||
None,
|
|
||||||
fallback_bundle,
|
fallback_bundle,
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
false,
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
TerminalUrl::No,
|
|
||||||
);
|
);
|
||||||
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
|
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
|
||||||
let sess = ParseSess::with_span_handler(handler, sm);
|
let sess = ParseSess::with_span_handler(handler, sm);
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use rustc_data_structures::sync::{Lrc, Send};
|
use rustc_data_structures::sync::{Lrc, Send};
|
||||||
use rustc_errors::emitter::{Emitter, EmitterWriter};
|
use rustc_errors::emitter::{Emitter, EmitterWriter};
|
||||||
use rustc_errors::translation::Translate;
|
use rustc_errors::translation::Translate;
|
||||||
use rustc_errors::{ColorConfig, Diagnostic, Handler, Level as DiagnosticLevel, TerminalUrl};
|
use rustc_errors::{ColorConfig, Diagnostic, Handler, Level as DiagnosticLevel};
|
||||||
use rustc_session::parse::ParseSess as RawParseSess;
|
use rustc_session::parse::ParseSess as RawParseSess;
|
||||||
use rustc_span::{
|
use rustc_span::{
|
||||||
source_map::{FilePathMapping, SourceMap},
|
source_map::{FilePathMapping, SourceMap},
|
||||||
|
@ -139,18 +139,7 @@ fn default_handler(
|
||||||
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
|
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
Box::new(EmitterWriter::stderr(
|
Box::new(EmitterWriter::stderr(emit_color, fallback_bundle).sm(Some(source_map.clone())))
|
||||||
emit_color,
|
|
||||||
Some(source_map.clone()),
|
|
||||||
None,
|
|
||||||
fallback_bundle,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
TerminalUrl::No,
|
|
||||||
))
|
|
||||||
};
|
};
|
||||||
Handler::with_emitter(Box::new(SilentOnIgnoredFilesEmitter {
|
Handler::with_emitter(Box::new(SilentOnIgnoredFilesEmitter {
|
||||||
has_non_ignorable_parser_errors: false,
|
has_non_ignorable_parser_errors: false,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue