Skip to content

Commit 6664c2c

Browse files
committed
fix: Respect HumanReadableErrorType::AnnotateSnippet
1 parent 4c23a70 commit 6664c2c

File tree

3 files changed

+90
-37
lines changed

3 files changed

+90
-37
lines changed

compiler/rustc_errors/src/json.rs

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use rustc_span::hygiene::ExpnData;
2525
use rustc_span::source_map::{FilePathMapping, SourceMap};
2626
use serde::Serialize;
2727

28+
use crate::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
2829
use crate::diagnostic::IsLint;
2930
use crate::emitter::{
3031
ColorConfig, Destination, Emitter, HumanEmitter, HumanReadableErrorType, OutputTheme,
@@ -378,21 +379,44 @@ impl Diagnostic {
378379
choice => choice,
379380
},
380381
);
381-
HumanEmitter::new(dst, je.translator.clone())
382-
.short_message(short)
383-
.sm(je.sm.clone())
384-
.diagnostic_width(je.diagnostic_width)
385-
.macro_backtrace(je.macro_backtrace)
386-
.track_diagnostics(je.track_diagnostics)
387-
.terminal_url(je.terminal_url)
388-
.ui_testing(je.ui_testing)
389-
.ignored_directories_in_source_blocks(je.ignored_directories_in_source_blocks.clone())
390-
.theme(if let HumanReadableErrorType::Unicode = je.json_rendered {
391-
OutputTheme::Unicode
392-
} else {
393-
OutputTheme::Ascii
394-
})
395-
.emit_diagnostic(diag, registry);
382+
if let HumanReadableErrorType::AnnotateSnippet = je.json_rendered {
383+
AnnotateSnippetEmitter::new(dst, je.translator.clone())
384+
.short_message(short)
385+
.sm(je.sm.clone())
386+
.diagnostic_width(je.diagnostic_width)
387+
.macro_backtrace(je.macro_backtrace)
388+
.track_diagnostics(je.track_diagnostics)
389+
.terminal_url(je.terminal_url)
390+
.ui_testing(je.ui_testing)
391+
.ignored_directories_in_source_blocks(
392+
je.ignored_directories_in_source_blocks.clone(),
393+
)
394+
.theme(if let HumanReadableErrorType::Unicode = je.json_rendered {
395+
OutputTheme::Unicode
396+
} else {
397+
OutputTheme::Ascii
398+
})
399+
.emit_diagnostic(diag, registry);
400+
} else {
401+
HumanEmitter::new(dst, je.translator.clone())
402+
.short_message(short)
403+
.sm(je.sm.clone())
404+
.diagnostic_width(je.diagnostic_width)
405+
.macro_backtrace(je.macro_backtrace)
406+
.track_diagnostics(je.track_diagnostics)
407+
.terminal_url(je.terminal_url)
408+
.ui_testing(je.ui_testing)
409+
.ignored_directories_in_source_blocks(
410+
je.ignored_directories_in_source_blocks.clone(),
411+
)
412+
.theme(if let HumanReadableErrorType::Unicode = je.json_rendered {
413+
OutputTheme::Unicode
414+
} else {
415+
OutputTheme::Ascii
416+
})
417+
.emit_diagnostic(diag, registry);
418+
}
419+
396420
let buf = Arc::try_unwrap(buf.0).unwrap().into_inner().unwrap();
397421
let buf = String::from_utf8(buf).unwrap();
398422

compiler/rustc_session/src/session.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,15 +1501,27 @@ fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
15011501
let emitter: Box<DynEmitter> = match output {
15021502
config::ErrorOutputType::HumanReadable { kind, color_config } => {
15031503
let short = kind.short();
1504-
Box::new(
1505-
HumanEmitter::new(stderr_destination(color_config), translator)
1506-
.theme(if let HumanReadableErrorType::Unicode = kind {
1507-
OutputTheme::Unicode
1508-
} else {
1509-
OutputTheme::Ascii
1510-
})
1511-
.short_message(short),
1512-
)
1504+
if let HumanReadableErrorType::AnnotateSnippet = kind {
1505+
Box::new(
1506+
AnnotateSnippetEmitter::new(stderr_destination(color_config), translator)
1507+
.theme(if let HumanReadableErrorType::Unicode = kind {
1508+
OutputTheme::Unicode
1509+
} else {
1510+
OutputTheme::Ascii
1511+
})
1512+
.short_message(short),
1513+
)
1514+
} else {
1515+
Box::new(
1516+
HumanEmitter::new(stderr_destination(color_config), translator)
1517+
.theme(if let HumanReadableErrorType::Unicode = kind {
1518+
OutputTheme::Unicode
1519+
} else {
1520+
OutputTheme::Ascii
1521+
})
1522+
.short_message(short),
1523+
)
1524+
}
15131525
}
15141526
config::ErrorOutputType::Json { pretty, json_rendered, color_config } => {
15151527
Box::new(JsonEmitter::new(

src/librustdoc/core.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
55
use rustc_data_structures::unord::UnordSet;
66
use rustc_driver::USING_INTERNAL_FEATURES;
77
use rustc_errors::TerminalUrl;
8+
use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
89
use rustc_errors::codes::*;
910
use rustc_errors::emitter::{
1011
DynEmitter, HumanEmitter, HumanReadableErrorType, OutputTheme, stderr_destination,
@@ -154,19 +155,35 @@ pub(crate) fn new_dcx(
154155
let emitter: Box<DynEmitter> = match error_format {
155156
ErrorOutputType::HumanReadable { kind, color_config } => {
156157
let short = kind.short();
157-
Box::new(
158-
HumanEmitter::new(stderr_destination(color_config), translator)
159-
.sm(source_map.map(|sm| sm as _))
160-
.short_message(short)
161-
.diagnostic_width(diagnostic_width)
162-
.track_diagnostics(unstable_opts.track_diagnostics)
163-
.theme(if let HumanReadableErrorType::Unicode = kind {
164-
OutputTheme::Unicode
165-
} else {
166-
OutputTheme::Ascii
167-
})
168-
.ui_testing(unstable_opts.ui_testing),
169-
)
158+
if let HumanReadableErrorType::AnnotateSnippet = kind {
159+
Box::new(
160+
AnnotateSnippetEmitter::new(stderr_destination(color_config), translator)
161+
.sm(source_map.map(|sm| sm as _))
162+
.short_message(short)
163+
.diagnostic_width(diagnostic_width)
164+
.track_diagnostics(unstable_opts.track_diagnostics)
165+
.theme(if let HumanReadableErrorType::Unicode = kind {
166+
OutputTheme::Unicode
167+
} else {
168+
OutputTheme::Ascii
169+
})
170+
.ui_testing(unstable_opts.ui_testing),
171+
)
172+
} else {
173+
Box::new(
174+
HumanEmitter::new(stderr_destination(color_config), translator)
175+
.sm(source_map.map(|sm| sm as _))
176+
.short_message(short)
177+
.diagnostic_width(diagnostic_width)
178+
.track_diagnostics(unstable_opts.track_diagnostics)
179+
.theme(if let HumanReadableErrorType::Unicode = kind {
180+
OutputTheme::Unicode
181+
} else {
182+
OutputTheme::Ascii
183+
})
184+
.ui_testing(unstable_opts.ui_testing),
185+
)
186+
}
170187
}
171188
ErrorOutputType::Json { pretty, json_rendered, color_config } => {
172189
let source_map = source_map.unwrap_or_else(|| {

0 commit comments

Comments
 (0)