mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
fix: Respect HumanReadableErrorType::AnnotateSnippet
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
use rustc_span::source_map::{FilePathMapping, SourceMap};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
|
||||
use crate::diagnostic::IsLint;
|
||||
use crate::emitter::{
|
||||
ColorConfig, Destination, Emitter, HumanEmitter, HumanReadableErrorType, OutputTheme,
|
||||
@@ -378,21 +379,44 @@ fn flush(&mut self) -> io::Result<()> {
|
||||
choice => choice,
|
||||
},
|
||||
);
|
||||
HumanEmitter::new(dst, je.translator.clone())
|
||||
.short_message(short)
|
||||
.sm(je.sm.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)
|
||||
.ignored_directories_in_source_blocks(je.ignored_directories_in_source_blocks.clone())
|
||||
.theme(if let HumanReadableErrorType::Unicode = je.json_rendered {
|
||||
OutputTheme::Unicode
|
||||
} else {
|
||||
OutputTheme::Ascii
|
||||
})
|
||||
.emit_diagnostic(diag, registry);
|
||||
if let HumanReadableErrorType::AnnotateSnippet = je.json_rendered {
|
||||
AnnotateSnippetEmitter::new(dst, je.translator.clone())
|
||||
.short_message(short)
|
||||
.sm(je.sm.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)
|
||||
.ignored_directories_in_source_blocks(
|
||||
je.ignored_directories_in_source_blocks.clone(),
|
||||
)
|
||||
.theme(if let HumanReadableErrorType::Unicode = je.json_rendered {
|
||||
OutputTheme::Unicode
|
||||
} else {
|
||||
OutputTheme::Ascii
|
||||
})
|
||||
.emit_diagnostic(diag, registry);
|
||||
} else {
|
||||
HumanEmitter::new(dst, je.translator.clone())
|
||||
.short_message(short)
|
||||
.sm(je.sm.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)
|
||||
.ignored_directories_in_source_blocks(
|
||||
je.ignored_directories_in_source_blocks.clone(),
|
||||
)
|
||||
.theme(if let HumanReadableErrorType::Unicode = je.json_rendered {
|
||||
OutputTheme::Unicode
|
||||
} else {
|
||||
OutputTheme::Ascii
|
||||
})
|
||||
.emit_diagnostic(diag, registry);
|
||||
}
|
||||
|
||||
let buf = Arc::try_unwrap(buf.0).unwrap().into_inner().unwrap();
|
||||
let buf = String::from_utf8(buf).unwrap();
|
||||
|
||||
|
||||
@@ -1501,15 +1501,27 @@ fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
|
||||
let emitter: Box<DynEmitter> = match output {
|
||||
config::ErrorOutputType::HumanReadable { kind, color_config } => {
|
||||
let short = kind.short();
|
||||
Box::new(
|
||||
HumanEmitter::new(stderr_destination(color_config), translator)
|
||||
.theme(if let HumanReadableErrorType::Unicode = kind {
|
||||
OutputTheme::Unicode
|
||||
} else {
|
||||
OutputTheme::Ascii
|
||||
})
|
||||
.short_message(short),
|
||||
)
|
||||
if let HumanReadableErrorType::AnnotateSnippet = kind {
|
||||
Box::new(
|
||||
AnnotateSnippetEmitter::new(stderr_destination(color_config), translator)
|
||||
.theme(if let HumanReadableErrorType::Unicode = kind {
|
||||
OutputTheme::Unicode
|
||||
} else {
|
||||
OutputTheme::Ascii
|
||||
})
|
||||
.short_message(short),
|
||||
)
|
||||
} else {
|
||||
Box::new(
|
||||
HumanEmitter::new(stderr_destination(color_config), translator)
|
||||
.theme(if let HumanReadableErrorType::Unicode = kind {
|
||||
OutputTheme::Unicode
|
||||
} else {
|
||||
OutputTheme::Ascii
|
||||
})
|
||||
.short_message(short),
|
||||
)
|
||||
}
|
||||
}
|
||||
config::ErrorOutputType::Json { pretty, json_rendered, color_config } => {
|
||||
Box::new(JsonEmitter::new(
|
||||
|
||||
+30
-13
@@ -5,6 +5,7 @@
|
||||
use rustc_data_structures::unord::UnordSet;
|
||||
use rustc_driver::USING_INTERNAL_FEATURES;
|
||||
use rustc_errors::TerminalUrl;
|
||||
use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
|
||||
use rustc_errors::codes::*;
|
||||
use rustc_errors::emitter::{
|
||||
DynEmitter, HumanEmitter, HumanReadableErrorType, OutputTheme, stderr_destination,
|
||||
@@ -154,19 +155,35 @@ pub(crate) fn new_dcx(
|
||||
let emitter: Box<DynEmitter> = match error_format {
|
||||
ErrorOutputType::HumanReadable { kind, color_config } => {
|
||||
let short = kind.short();
|
||||
Box::new(
|
||||
HumanEmitter::new(stderr_destination(color_config), translator)
|
||||
.sm(source_map.map(|sm| sm as _))
|
||||
.short_message(short)
|
||||
.diagnostic_width(diagnostic_width)
|
||||
.track_diagnostics(unstable_opts.track_diagnostics)
|
||||
.theme(if let HumanReadableErrorType::Unicode = kind {
|
||||
OutputTheme::Unicode
|
||||
} else {
|
||||
OutputTheme::Ascii
|
||||
})
|
||||
.ui_testing(unstable_opts.ui_testing),
|
||||
)
|
||||
if let HumanReadableErrorType::AnnotateSnippet = kind {
|
||||
Box::new(
|
||||
AnnotateSnippetEmitter::new(stderr_destination(color_config), translator)
|
||||
.sm(source_map.map(|sm| sm as _))
|
||||
.short_message(short)
|
||||
.diagnostic_width(diagnostic_width)
|
||||
.track_diagnostics(unstable_opts.track_diagnostics)
|
||||
.theme(if let HumanReadableErrorType::Unicode = kind {
|
||||
OutputTheme::Unicode
|
||||
} else {
|
||||
OutputTheme::Ascii
|
||||
})
|
||||
.ui_testing(unstable_opts.ui_testing),
|
||||
)
|
||||
} else {
|
||||
Box::new(
|
||||
HumanEmitter::new(stderr_destination(color_config), translator)
|
||||
.sm(source_map.map(|sm| sm as _))
|
||||
.short_message(short)
|
||||
.diagnostic_width(diagnostic_width)
|
||||
.track_diagnostics(unstable_opts.track_diagnostics)
|
||||
.theme(if let HumanReadableErrorType::Unicode = kind {
|
||||
OutputTheme::Unicode
|
||||
} else {
|
||||
OutputTheme::Ascii
|
||||
})
|
||||
.ui_testing(unstable_opts.ui_testing),
|
||||
)
|
||||
}
|
||||
}
|
||||
ErrorOutputType::Json { pretty, json_rendered, color_config } => {
|
||||
let source_map = source_map.unwrap_or_else(|| {
|
||||
|
||||
Reference in New Issue
Block a user