Replace DiagnosticBuilder with Diagnostic when emitting error
This commit is contained in:
parent
5670d048c0
commit
cdd805506e
11 changed files with 60 additions and 26 deletions
|
@ -1040,6 +1040,7 @@ fn default_emitter(
|
||||||
source_map: &Lrc<source_map::SourceMap>,
|
source_map: &Lrc<source_map::SourceMap>,
|
||||||
emitter_dest: Option<Box<dyn Write + Send>>,
|
emitter_dest: Option<Box<dyn Write + Send>>,
|
||||||
) -> Box<dyn Emitter + sync::Send> {
|
) -> Box<dyn Emitter + sync::Send> {
|
||||||
|
let external_macro_backtrace = sopts.debugging_opts.external_macro_backtrace;
|
||||||
match (sopts.error_format, emitter_dest) {
|
match (sopts.error_format, emitter_dest) {
|
||||||
(config::ErrorOutputType::HumanReadable(kind), dst) => {
|
(config::ErrorOutputType::HumanReadable(kind), dst) => {
|
||||||
let (short, color_config) = kind.unzip();
|
let (short, color_config) = kind.unzip();
|
||||||
|
@ -1048,6 +1049,7 @@ fn default_emitter(
|
||||||
let emitter = AnnotateSnippetEmitterWriter::new(
|
let emitter = AnnotateSnippetEmitterWriter::new(
|
||||||
Some(source_map.clone()),
|
Some(source_map.clone()),
|
||||||
short,
|
short,
|
||||||
|
external_macro_backtrace,
|
||||||
);
|
);
|
||||||
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
|
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
|
||||||
} else {
|
} else {
|
||||||
|
@ -1058,6 +1060,7 @@ fn default_emitter(
|
||||||
short,
|
short,
|
||||||
sopts.debugging_opts.teach,
|
sopts.debugging_opts.teach,
|
||||||
sopts.debugging_opts.terminal_width,
|
sopts.debugging_opts.terminal_width,
|
||||||
|
external_macro_backtrace,
|
||||||
),
|
),
|
||||||
Some(dst) => EmitterWriter::new(
|
Some(dst) => EmitterWriter::new(
|
||||||
dst,
|
dst,
|
||||||
|
@ -1066,6 +1069,7 @@ fn default_emitter(
|
||||||
false, // no teach messages when writing to a buffer
|
false, // no teach messages when writing to a buffer
|
||||||
false, // no colors when writing to a buffer
|
false, // no colors when writing to a buffer
|
||||||
None, // no terminal width
|
None, // no terminal width
|
||||||
|
external_macro_backtrace,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
|
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
|
||||||
|
@ -1077,6 +1081,7 @@ fn default_emitter(
|
||||||
source_map.clone(),
|
source_map.clone(),
|
||||||
pretty,
|
pretty,
|
||||||
json_rendered,
|
json_rendered,
|
||||||
|
external_macro_backtrace,
|
||||||
).ui_testing(sopts.debugging_opts.ui_testing),
|
).ui_testing(sopts.debugging_opts.ui_testing),
|
||||||
),
|
),
|
||||||
(config::ErrorOutputType::Json { pretty, json_rendered }, Some(dst)) => Box::new(
|
(config::ErrorOutputType::Json { pretty, json_rendered }, Some(dst)) => Box::new(
|
||||||
|
@ -1086,6 +1091,7 @@ fn default_emitter(
|
||||||
source_map.clone(),
|
source_map.clone(),
|
||||||
pretty,
|
pretty,
|
||||||
json_rendered,
|
json_rendered,
|
||||||
|
external_macro_backtrace,
|
||||||
).ui_testing(sopts.debugging_opts.ui_testing),
|
).ui_testing(sopts.debugging_opts.ui_testing),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
@ -1382,10 +1388,10 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
|
||||||
let emitter: Box<dyn Emitter + sync::Send> = match output {
|
let emitter: Box<dyn Emitter + sync::Send> = match output {
|
||||||
config::ErrorOutputType::HumanReadable(kind) => {
|
config::ErrorOutputType::HumanReadable(kind) => {
|
||||||
let (short, color_config) = kind.unzip();
|
let (short, color_config) = kind.unzip();
|
||||||
Box::new(EmitterWriter::stderr(color_config, None, short, false, None))
|
Box::new(EmitterWriter::stderr(color_config, None, short, false, None, false))
|
||||||
}
|
}
|
||||||
config::ErrorOutputType::Json { pretty, json_rendered } =>
|
config::ErrorOutputType::Json { pretty, json_rendered } =>
|
||||||
Box::new(JsonEmitter::basic(pretty, json_rendered)),
|
Box::new(JsonEmitter::basic(pretty, json_rendered, false)),
|
||||||
};
|
};
|
||||||
let handler = errors::Handler::with_emitter(true, None, emitter);
|
let handler = errors::Handler::with_emitter(true, None, emitter);
|
||||||
handler.emit(&MultiSpan::new(), msg, errors::Level::Fatal);
|
handler.emit(&MultiSpan::new(), msg, errors::Level::Fatal);
|
||||||
|
@ -1396,10 +1402,10 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
|
||||||
let emitter: Box<dyn Emitter + sync::Send> = match output {
|
let emitter: Box<dyn Emitter + sync::Send> = match output {
|
||||||
config::ErrorOutputType::HumanReadable(kind) => {
|
config::ErrorOutputType::HumanReadable(kind) => {
|
||||||
let (short, color_config) = kind.unzip();
|
let (short, color_config) = kind.unzip();
|
||||||
Box::new(EmitterWriter::stderr(color_config, None, short, false, None))
|
Box::new(EmitterWriter::stderr(color_config, None, short, false, None, false))
|
||||||
}
|
}
|
||||||
config::ErrorOutputType::Json { pretty, json_rendered } =>
|
config::ErrorOutputType::Json { pretty, json_rendered } =>
|
||||||
Box::new(JsonEmitter::basic(pretty, json_rendered)),
|
Box::new(JsonEmitter::basic(pretty, json_rendered, false)),
|
||||||
};
|
};
|
||||||
let handler = errors::Handler::with_emitter(true, None, emitter);
|
let handler = errors::Handler::with_emitter(true, None, emitter);
|
||||||
handler.emit(&MultiSpan::new(), msg, errors::Level::Warning);
|
handler.emit(&MultiSpan::new(), msg, errors::Level::Warning);
|
||||||
|
|
|
@ -22,7 +22,7 @@ use rustc::util::common::{time_depth, set_time_depth, print_time_passes_entry};
|
||||||
use rustc::util::profiling::SelfProfiler;
|
use rustc::util::profiling::SelfProfiler;
|
||||||
use rustc_fs_util::link_or_copy;
|
use rustc_fs_util::link_or_copy;
|
||||||
use rustc_data_structures::svh::Svh;
|
use rustc_data_structures::svh::Svh;
|
||||||
use rustc_errors::{Handler, Level, DiagnosticBuilder, FatalError, DiagnosticId};
|
use rustc_errors::{Handler, Level, FatalError, DiagnosticId};
|
||||||
use rustc_errors::emitter::{Emitter};
|
use rustc_errors::emitter::{Emitter};
|
||||||
use rustc_target::spec::MergeFunctions;
|
use rustc_target::spec::MergeFunctions;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
|
@ -1725,7 +1725,7 @@ impl SharedEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for SharedEmitter {
|
impl Emitter for SharedEmitter {
|
||||||
fn emit_diagnostic(&mut self, db: &DiagnosticBuilder<'_>) {
|
fn emit_diagnostic(&mut self, db: &rustc_errors::Diagnostic) {
|
||||||
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
||||||
msg: db.message(),
|
msg: db.message(),
|
||||||
code: db.code.clone(),
|
code: db.code.clone(),
|
||||||
|
|
|
@ -1196,6 +1196,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
None,
|
None,
|
||||||
|
false,
|
||||||
));
|
));
|
||||||
let handler = errors::Handler::with_emitter(true, None, emitter);
|
let handler = errors::Handler::with_emitter(true, None, emitter);
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
use syntax_pos::{SourceFile, MultiSpan, Loc};
|
use syntax_pos::{SourceFile, MultiSpan, Loc};
|
||||||
use crate::{
|
use crate::{
|
||||||
Level, CodeSuggestion, DiagnosticBuilder, Emitter,
|
Level, CodeSuggestion, Diagnostic, Emitter,
|
||||||
SourceMapperDyn, SubDiagnostic, DiagnosticId
|
SourceMapperDyn, SubDiagnostic, DiagnosticId
|
||||||
};
|
};
|
||||||
use crate::emitter::FileWithAnnotatedLines;
|
use crate::emitter::FileWithAnnotatedLines;
|
||||||
|
@ -25,11 +25,13 @@ pub struct AnnotateSnippetEmitterWriter {
|
||||||
short_message: bool,
|
short_message: bool,
|
||||||
/// If true, will normalize line numbers with `LL` to prevent noise in UI test diffs.
|
/// If true, will normalize line numbers with `LL` to prevent noise in UI test diffs.
|
||||||
ui_testing: bool,
|
ui_testing: bool,
|
||||||
|
|
||||||
|
external_macro_backtrace: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for AnnotateSnippetEmitterWriter {
|
impl Emitter for AnnotateSnippetEmitterWriter {
|
||||||
/// The entry point for the diagnostics generation
|
/// The entry point for the diagnostics generation
|
||||||
fn emit_diagnostic(&mut self, db: &DiagnosticBuilder<'_>) {
|
fn emit_diagnostic(&mut self, db: &Diagnostic) {
|
||||||
let mut children = db.children.clone();
|
let mut children = db.children.clone();
|
||||||
let (mut primary_span, suggestions) = self.primary_span_formatted(&db);
|
let (mut primary_span, suggestions) = self.primary_span_formatted(&db);
|
||||||
|
|
||||||
|
@ -37,7 +39,7 @@ impl Emitter for AnnotateSnippetEmitterWriter {
|
||||||
&mut primary_span,
|
&mut primary_span,
|
||||||
&mut children,
|
&mut children,
|
||||||
&db.level,
|
&db.level,
|
||||||
db.handler().flags.external_macro_backtrace);
|
self.external_macro_backtrace);
|
||||||
|
|
||||||
self.emit_messages_default(&db.level,
|
self.emit_messages_default(&db.level,
|
||||||
db.message(),
|
db.message(),
|
||||||
|
@ -163,12 +165,14 @@ impl<'a> DiagnosticConverter<'a> {
|
||||||
impl AnnotateSnippetEmitterWriter {
|
impl AnnotateSnippetEmitterWriter {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
source_map: Option<Lrc<SourceMapperDyn>>,
|
source_map: Option<Lrc<SourceMapperDyn>>,
|
||||||
short_message: bool
|
short_message: bool,
|
||||||
|
external_macro_backtrace: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
source_map,
|
source_map,
|
||||||
short_message,
|
short_message,
|
||||||
ui_testing: false,
|
ui_testing: false,
|
||||||
|
external_macro_backtrace,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ use Destination::*;
|
||||||
use syntax_pos::{SourceFile, Span, MultiSpan};
|
use syntax_pos::{SourceFile, Span, MultiSpan};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic,
|
Level, CodeSuggestion, Diagnostic, SubDiagnostic,
|
||||||
SuggestionStyle, SourceMapperDyn, DiagnosticId,
|
SuggestionStyle, SourceMapperDyn, DiagnosticId,
|
||||||
};
|
};
|
||||||
use crate::Level::Error;
|
use crate::Level::Error;
|
||||||
|
@ -52,10 +52,12 @@ impl HumanReadableErrorType {
|
||||||
source_map: Option<Lrc<SourceMapperDyn>>,
|
source_map: Option<Lrc<SourceMapperDyn>>,
|
||||||
teach: bool,
|
teach: bool,
|
||||||
terminal_width: Option<usize>,
|
terminal_width: Option<usize>,
|
||||||
|
external_macro_backtrace: bool,
|
||||||
) -> 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(dst, source_map, short, teach, color, terminal_width)
|
EmitterWriter::new(dst, source_map, short, teach, color, terminal_width,
|
||||||
|
external_macro_backtrace)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +182,7 @@ const ANONYMIZED_LINE_NUM: &str = "LL";
|
||||||
/// Emitter trait for emitting errors.
|
/// Emitter trait for emitting errors.
|
||||||
pub trait Emitter {
|
pub trait Emitter {
|
||||||
/// Emit a structured diagnostic.
|
/// Emit a structured diagnostic.
|
||||||
fn emit_diagnostic(&mut self, db: &DiagnosticBuilder<'_>);
|
fn emit_diagnostic(&mut self, db: &Diagnostic);
|
||||||
|
|
||||||
/// Emit a notification that an artifact has been output.
|
/// Emit a notification that an artifact has been output.
|
||||||
/// This is currently only supported for the JSON format,
|
/// This is currently only supported for the JSON format,
|
||||||
|
@ -204,7 +206,7 @@ pub trait Emitter {
|
||||||
/// we return the original `primary_span` and the original suggestions.
|
/// we return the original `primary_span` and the original suggestions.
|
||||||
fn primary_span_formatted<'a>(
|
fn primary_span_formatted<'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
db: &'a DiagnosticBuilder<'_>
|
db: &'a Diagnostic
|
||||||
) -> (MultiSpan, &'a [CodeSuggestion]) {
|
) -> (MultiSpan, &'a [CodeSuggestion]) {
|
||||||
let mut primary_span = db.span.clone();
|
let mut primary_span = db.span.clone();
|
||||||
if let Some((sugg, rest)) = db.suggestions.split_first() {
|
if let Some((sugg, rest)) = db.suggestions.split_first() {
|
||||||
|
@ -377,7 +379,7 @@ pub trait Emitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for EmitterWriter {
|
impl Emitter for EmitterWriter {
|
||||||
fn emit_diagnostic(&mut self, db: &DiagnosticBuilder<'_>) {
|
fn emit_diagnostic(&mut self, db: &Diagnostic) {
|
||||||
let mut children = db.children.clone();
|
let mut children = db.children.clone();
|
||||||
let (mut primary_span, suggestions) = self.primary_span_formatted(&db);
|
let (mut primary_span, suggestions) = self.primary_span_formatted(&db);
|
||||||
|
|
||||||
|
@ -385,7 +387,7 @@ impl Emitter for EmitterWriter {
|
||||||
&mut primary_span,
|
&mut primary_span,
|
||||||
&mut children,
|
&mut children,
|
||||||
&db.level,
|
&db.level,
|
||||||
db.handler().flags.external_macro_backtrace);
|
self.external_macro_backtrace);
|
||||||
|
|
||||||
self.emit_messages_default(&db.level,
|
self.emit_messages_default(&db.level,
|
||||||
&db.styled_message(),
|
&db.styled_message(),
|
||||||
|
@ -449,6 +451,8 @@ pub struct EmitterWriter {
|
||||||
teach: bool,
|
teach: bool,
|
||||||
ui_testing: bool,
|
ui_testing: bool,
|
||||||
terminal_width: Option<usize>,
|
terminal_width: Option<usize>,
|
||||||
|
|
||||||
|
external_macro_backtrace: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -465,6 +469,7 @@ impl EmitterWriter {
|
||||||
short_message: bool,
|
short_message: bool,
|
||||||
teach: bool,
|
teach: bool,
|
||||||
terminal_width: Option<usize>,
|
terminal_width: Option<usize>,
|
||||||
|
external_macro_backtrace: bool,
|
||||||
) -> EmitterWriter {
|
) -> EmitterWriter {
|
||||||
let dst = Destination::from_stderr(color_config);
|
let dst = Destination::from_stderr(color_config);
|
||||||
EmitterWriter {
|
EmitterWriter {
|
||||||
|
@ -474,6 +479,7 @@ impl EmitterWriter {
|
||||||
teach,
|
teach,
|
||||||
ui_testing: false,
|
ui_testing: false,
|
||||||
terminal_width,
|
terminal_width,
|
||||||
|
external_macro_backtrace,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,6 +490,7 @@ impl EmitterWriter {
|
||||||
teach: bool,
|
teach: bool,
|
||||||
colored: bool,
|
colored: bool,
|
||||||
terminal_width: Option<usize>,
|
terminal_width: Option<usize>,
|
||||||
|
external_macro_backtrace: bool,
|
||||||
) -> EmitterWriter {
|
) -> EmitterWriter {
|
||||||
EmitterWriter {
|
EmitterWriter {
|
||||||
dst: Raw(dst, colored),
|
dst: Raw(dst, colored),
|
||||||
|
@ -492,6 +499,7 @@ impl EmitterWriter {
|
||||||
teach,
|
teach,
|
||||||
ui_testing: false,
|
ui_testing: false,
|
||||||
terminal_width,
|
terminal_width,
|
||||||
|
external_macro_backtrace,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -383,7 +383,8 @@ impl Handler {
|
||||||
cm: Option<Lrc<SourceMapperDyn>>,
|
cm: Option<Lrc<SourceMapperDyn>>,
|
||||||
flags: HandlerFlags)
|
flags: HandlerFlags)
|
||||||
-> Handler {
|
-> Handler {
|
||||||
let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false, false, None));
|
let emitter = Box::new(EmitterWriter::stderr(
|
||||||
|
color_config, cm, false, false, None, flags.external_macro_backtrace));
|
||||||
Handler::with_emitter_and_flags(emitter, flags)
|
Handler::with_emitter_and_flags(emitter, flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,6 +193,7 @@ pub fn new_handler(error_format: ErrorOutputType,
|
||||||
short,
|
short,
|
||||||
sessopts.debugging_opts.teach,
|
sessopts.debugging_opts.teach,
|
||||||
sessopts.debugging_opts.terminal_width,
|
sessopts.debugging_opts.terminal_width,
|
||||||
|
false,
|
||||||
).ui_testing(ui_testing)
|
).ui_testing(ui_testing)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -205,6 +206,7 @@ pub fn new_handler(error_format: ErrorOutputType,
|
||||||
source_map,
|
source_map,
|
||||||
pretty,
|
pretty,
|
||||||
json_rendered,
|
json_rendered,
|
||||||
|
false,
|
||||||
).ui_testing(ui_testing)
|
).ui_testing(ui_testing)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
|
@ -401,7 +401,7 @@ pub fn make_test(s: &str,
|
||||||
// Any errors in parsing should also appear when the doctest is compiled for real, so just
|
// Any errors in parsing should also appear when the doctest is compiled for real, so just
|
||||||
// send all the errors that libsyntax emits directly into a `Sink` instead of stderr.
|
// send all the errors that libsyntax emits directly into a `Sink` instead of stderr.
|
||||||
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
||||||
let emitter = EmitterWriter::new(box io::sink(), None, false, false, false, None);
|
let emitter = EmitterWriter::new(box io::sink(), None, false, false, false, None, false);
|
||||||
// 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(false, None, box emitter);
|
let handler = Handler::with_emitter(false, None, box emitter);
|
||||||
let sess = ParseSess::with_span_handler(handler, cm);
|
let sess = ParseSess::with_span_handler(handler, cm);
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
use crate::source_map::{SourceMap, FilePathMapping};
|
use crate::source_map::{SourceMap, FilePathMapping};
|
||||||
|
|
||||||
use errors::registry::Registry;
|
use errors::registry::Registry;
|
||||||
use errors::{DiagnosticBuilder, SubDiagnostic, CodeSuggestion, SourceMapper};
|
use errors::{SubDiagnostic, CodeSuggestion, SourceMapper};
|
||||||
use errors::{DiagnosticId, Applicability};
|
use errors::{DiagnosticId, Applicability};
|
||||||
use errors::emitter::{Emitter, HumanReadableErrorType};
|
use errors::emitter::{Emitter, HumanReadableErrorType};
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ pub struct JsonEmitter {
|
||||||
pretty: bool,
|
pretty: bool,
|
||||||
ui_testing: bool,
|
ui_testing: bool,
|
||||||
json_rendered: HumanReadableErrorType,
|
json_rendered: HumanReadableErrorType,
|
||||||
|
external_macro_backtrace: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JsonEmitter {
|
impl JsonEmitter {
|
||||||
|
@ -40,6 +41,7 @@ impl JsonEmitter {
|
||||||
source_map: Lrc<SourceMap>,
|
source_map: Lrc<SourceMap>,
|
||||||
pretty: bool,
|
pretty: bool,
|
||||||
json_rendered: HumanReadableErrorType,
|
json_rendered: HumanReadableErrorType,
|
||||||
|
external_macro_backtrace: bool,
|
||||||
) -> JsonEmitter {
|
) -> JsonEmitter {
|
||||||
JsonEmitter {
|
JsonEmitter {
|
||||||
dst: Box::new(io::stderr()),
|
dst: Box::new(io::stderr()),
|
||||||
|
@ -48,13 +50,18 @@ impl JsonEmitter {
|
||||||
pretty,
|
pretty,
|
||||||
ui_testing: false,
|
ui_testing: false,
|
||||||
json_rendered,
|
json_rendered,
|
||||||
|
external_macro_backtrace,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn basic(pretty: bool, json_rendered: HumanReadableErrorType) -> JsonEmitter {
|
pub fn basic(
|
||||||
|
pretty: bool,
|
||||||
|
json_rendered: HumanReadableErrorType,
|
||||||
|
external_macro_backtrace: bool,
|
||||||
|
) -> JsonEmitter {
|
||||||
let file_path_mapping = FilePathMapping::empty();
|
let file_path_mapping = FilePathMapping::empty();
|
||||||
JsonEmitter::stderr(None, Lrc::new(SourceMap::new(file_path_mapping)),
|
JsonEmitter::stderr(None, Lrc::new(SourceMap::new(file_path_mapping)),
|
||||||
pretty, json_rendered)
|
pretty, json_rendered, external_macro_backtrace)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
@ -63,6 +70,7 @@ impl JsonEmitter {
|
||||||
source_map: Lrc<SourceMap>,
|
source_map: Lrc<SourceMap>,
|
||||||
pretty: bool,
|
pretty: bool,
|
||||||
json_rendered: HumanReadableErrorType,
|
json_rendered: HumanReadableErrorType,
|
||||||
|
external_macro_backtrace: bool,
|
||||||
) -> JsonEmitter {
|
) -> JsonEmitter {
|
||||||
JsonEmitter {
|
JsonEmitter {
|
||||||
dst,
|
dst,
|
||||||
|
@ -71,6 +79,7 @@ impl JsonEmitter {
|
||||||
pretty,
|
pretty,
|
||||||
ui_testing: false,
|
ui_testing: false,
|
||||||
json_rendered,
|
json_rendered,
|
||||||
|
external_macro_backtrace,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,8 +89,8 @@ impl JsonEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for JsonEmitter {
|
impl Emitter for JsonEmitter {
|
||||||
fn emit_diagnostic(&mut self, db: &DiagnosticBuilder<'_>) {
|
fn emit_diagnostic(&mut self, db: &errors::Diagnostic) {
|
||||||
let data = Diagnostic::from_diagnostic_builder(db, self);
|
let data = Diagnostic::from_errors_diagnostic(db, self);
|
||||||
let result = if self.pretty {
|
let result = if self.pretty {
|
||||||
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
|
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
|
||||||
} else {
|
} else {
|
||||||
|
@ -189,7 +198,7 @@ struct ArtifactNotification<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Diagnostic {
|
impl Diagnostic {
|
||||||
fn from_diagnostic_builder(db: &DiagnosticBuilder<'_>,
|
fn from_errors_diagnostic(db: &errors::Diagnostic,
|
||||||
je: &JsonEmitter)
|
je: &JsonEmitter)
|
||||||
-> Diagnostic {
|
-> Diagnostic {
|
||||||
let sugg = db.suggestions.iter().map(|sugg| {
|
let sugg = db.suggestions.iter().map(|sugg| {
|
||||||
|
@ -219,8 +228,9 @@ impl Diagnostic {
|
||||||
}
|
}
|
||||||
let buf = BufWriter::default();
|
let buf = BufWriter::default();
|
||||||
let output = buf.clone();
|
let output = buf.clone();
|
||||||
je.json_rendered.new_emitter(Box::new(buf), Some(je.sm.clone()), false, None)
|
je.json_rendered.new_emitter(
|
||||||
.ui_testing(je.ui_testing).emit_diagnostic(db);
|
Box::new(buf), Some(je.sm.clone()), false, None, je.external_macro_backtrace
|
||||||
|
).ui_testing(je.ui_testing).emit_diagnostic(db);
|
||||||
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
|
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
|
||||||
let output = String::from_utf8(output).unwrap();
|
let output = String::from_utf8(output).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ fn mk_sess(sm: Lrc<SourceMap>) -> ParseSess {
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
None,
|
None,
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
ParseSess::with_span_handler(Handler::with_emitter(true, None, Box::new(emitter)), sm)
|
ParseSess::with_span_handler(Handler::with_emitter(true, None, Box::new(emitter)), sm)
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,6 +147,7 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
None,
|
None,
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
let handler = Handler::with_emitter(true, None, Box::new(emitter));
|
let handler = Handler::with_emitter(true, None, Box::new(emitter));
|
||||||
handler.span_err(msp, "foo");
|
handler.span_err(msp, "foo");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue