Skip to content

Commit 4bffcdc

Browse files
committed
feat: Use annotate-snippets as the default renderer
1 parent 9d5eff1 commit 4bffcdc

File tree

8 files changed

+68
-101
lines changed

8 files changed

+68
-101
lines changed

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::fmt::Debug;
1111
use std::io;
1212
use std::sync::Arc;
1313

14-
use annotate_snippets::{AnnotationKind, Group, Padding, Patch, Renderer, Snippet};
14+
use annotate_snippets::{AnnotationKind, Group, Padding, Patch, Renderer, Snippet, debug_groups};
1515
use derive_setters::Setters;
1616
use rustc_data_structures::sync::IntoDynSyncSend;
1717
use rustc_error_messages::{FluentArgs, SpanLabel};
@@ -643,7 +643,8 @@ impl AnnotateSnippetEmitter {
643643
if !group.is_empty() {
644644
groups.push(group);
645645
}
646-
info!("{groups:#?}");
646+
//info!("{groups:#?}");
647+
info!("{}", debug_groups(&groups, &renderer).unwrap());
647648
if let Err(e) =
648649
emit_to_destination(renderer.render(&groups), level, &mut self.dst, self.short_message)
649650
{

compiler/rustc_errors/src/emitter.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use rustc_span::source_map::SourceMap;
2828
use rustc_span::{FileLines, FileName, SourceFile, Span, char_width, str_width};
2929
use tracing::{debug, info, instrument, trace, warn};
3030

31+
use crate::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
3132
use crate::registry::Registry;
3233
use crate::snippet::{
3334
Annotation, AnnotationColumn, AnnotationType, Line, MultilineAnnotation, Style, StyledString,
@@ -647,20 +648,8 @@ pub(crate) struct FileWithAnnotatedLines {
647648
}
648649

649650
impl HumanEmitter {
650-
pub fn new(dst: Destination, translator: Translator) -> HumanEmitter {
651-
HumanEmitter {
652-
dst: IntoDynSyncSend(dst),
653-
sm: None,
654-
translator,
655-
short_message: false,
656-
ui_testing: false,
657-
ignored_directories_in_source_blocks: Vec::new(),
658-
diagnostic_width: None,
659-
macro_backtrace: false,
660-
track_diagnostics: false,
661-
terminal_url: TerminalUrl::No,
662-
theme: OutputTheme::Ascii,
663-
}
651+
pub fn new(dst: Destination, translator: Translator) -> AnnotateSnippetEmitter {
652+
AnnotateSnippetEmitter::new(dst, translator)
664653
}
665654

666655
fn maybe_anonymized(&self, line_num: usize) -> Cow<'static, str> {

compiler/rustc_session/src/session.rs

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -981,45 +981,22 @@ fn default_emitter(
981981
config::ErrorOutputType::HumanReadable { kind, color_config } => {
982982
let short = kind.short();
983983

984-
if let HumanReadableErrorType::AnnotateSnippet = kind {
985-
let emitter =
986-
AnnotateSnippetEmitter::new(stderr_destination(color_config), translator)
987-
.sm(source_map)
988-
.short_message(short)
989-
.diagnostic_width(sopts.diagnostic_width)
990-
.macro_backtrace(macro_backtrace)
991-
.track_diagnostics(track_diagnostics)
992-
.terminal_url(terminal_url)
993-
.theme(if let HumanReadableErrorType::Unicode = kind {
994-
OutputTheme::Unicode
995-
} else {
996-
OutputTheme::Ascii
997-
})
998-
.ignored_directories_in_source_blocks(
999-
sopts
1000-
.unstable_opts
1001-
.ignore_directory_in_diagnostics_source_blocks
1002-
.clone(),
1003-
);
1004-
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
1005-
} else {
1006-
let emitter = HumanEmitter::new(stderr_destination(color_config), translator)
1007-
.sm(source_map)
1008-
.short_message(short)
1009-
.diagnostic_width(sopts.diagnostic_width)
1010-
.macro_backtrace(macro_backtrace)
1011-
.track_diagnostics(track_diagnostics)
1012-
.terminal_url(terminal_url)
1013-
.theme(if let HumanReadableErrorType::Unicode = kind {
1014-
OutputTheme::Unicode
1015-
} else {
1016-
OutputTheme::Ascii
1017-
})
1018-
.ignored_directories_in_source_blocks(
1019-
sopts.unstable_opts.ignore_directory_in_diagnostics_source_blocks.clone(),
1020-
);
1021-
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
1022-
}
984+
let emitter = AnnotateSnippetEmitter::new(stderr_destination(color_config), translator)
985+
.sm(source_map)
986+
.short_message(short)
987+
.diagnostic_width(sopts.diagnostic_width)
988+
.macro_backtrace(macro_backtrace)
989+
.track_diagnostics(track_diagnostics)
990+
.terminal_url(terminal_url)
991+
.theme(if let HumanReadableErrorType::Unicode = kind {
992+
OutputTheme::Unicode
993+
} else {
994+
OutputTheme::Ascii
995+
})
996+
.ignored_directories_in_source_blocks(
997+
sopts.unstable_opts.ignore_directory_in_diagnostics_source_blocks.clone(),
998+
);
999+
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
10231000
}
10241001
config::ErrorOutputType::Json { pretty, json_rendered, color_config } => Box::new(
10251002
JsonEmitter::new(

tests/ui/diagnostic-width/non-1-width-unicode-multiline-label.ascii.stderr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0369]: cannot add `&str` to `&str`
22
--> $DIR/non-1-width-unicode-multiline-label.rs:7:237
33
|
4-
LL | ...👧👦👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
5-
| -------------- ^ -------------- &str
6-
| | |
7-
| | `+` cannot be used to concatenate two `&str` strings
8-
| &str
4+
LL | ... 👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!"
5+
| -------------- ^ -------------- &str
6+
| | |
7+
| | `+` cannot be used to concatenate two `&str` strings
8+
| &str
99
|
1010
= note: string concatenation requires an owned `String` on the left
1111
help: create an owned `String` from a string reference
@@ -16,11 +16,11 @@ LL | let _ = "👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧
1616
error[E0369]: cannot add `&str` to `&str`
1717
--> $DIR/non-1-width-unicode-multiline-label.rs:9:384
1818
|
19-
LL | ...👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
20-
| -------------- ^ -------------- &str
21-
| | |
22-
| | `+` cannot be used to concatenate two `&str` strings
23-
| &str
19+
LL | ... 👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!"
20+
| -------------- ^ -------------- &str
21+
| | |
22+
| | `+` cannot be used to concatenate two `&str` strings
23+
| &str
2424
|
2525
= note: string concatenation requires an owned `String` on the left
2626
help: create an owned `String` from a string reference
@@ -32,10 +32,10 @@ error[E0369]: cannot add `&str` to `&str`
3232
--> $DIR/non-1-width-unicode-multiline-label.rs:11:260
3333
|
3434
LL | ...࿉࿊࿋࿌࿍࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun + " really fun!";
35-
| -------------- ^ -------------- &str
36-
| | |
37-
| | `+` cannot be used to concatenate two `&str` strings
38-
| &str
35+
| -------------- ^ -------------- &str
36+
| | |
37+
| | `+` cannot be used to concatenate two `&str` strings
38+
| &str
3939
|
4040
= note: string concatenation requires an owned `String` on the left
4141
help: create an owned `String` from a string reference

tests/ui/diagnostic-width/non-1-width-unicode-multiline-label.unicode.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0369]: cannot add `&str` to `&str`
22
╭▸ $DIR/non-1-width-unicode-multiline-label.rs:7:237
33
4-
LL │ …👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
5-
┬───────────── ┯ ────────────── &str
6-
│ │
7-
│ `+` cannot be used to concatenate two `&str` strings
8-
&str
4+
LL │ … 👧👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!"
5+
│ ┬───────────── ┯ ────────────── &str
6+
│ │ │
7+
│ │ `+` cannot be used to concatenate two `&str` strings
8+
│ &str
99
1010
╰ note: string concatenation requires an owned `String` on the left
1111
help: create an owned `String` from a string reference
@@ -16,11 +16,11 @@ LL │ let _ = "👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧
1616
error[E0369]: cannot add `&str` to `&str`
1717
╭▸ $DIR/non-1-width-unicode-multiline-label.rs:9:384
1818
19-
LL │ …👩👧👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
20-
┬───────────── ┯ ────────────── &str
21-
│ │
22-
│ `+` cannot be used to concatenate two `&str` strings
23-
&str
19+
LL │ … 👧👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!"
20+
│ ┬───────────── ┯ ────────────── &str
21+
│ │ │
22+
│ │ `+` cannot be used to concatenate two `&str` strings
23+
│ &str
2424
2525
╰ note: string concatenation requires an owned `String` on the left
2626
help: create an owned `String` from a string reference
@@ -31,11 +31,11 @@ LL │ let _ = "👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧
3131
error[E0369]: cannot add `&str` to `&str`
3232
╭▸ $DIR/non-1-width-unicode-multiline-label.rs:11:260
3333
34-
LL │ …࿇࿈࿉࿊࿋࿌࿍࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun + " really fun!";
35-
│ ┬───────────── ┯ ────────────── &str
36-
│ │ │
37-
│ │ `+` cannot be used to concatenate two `&str` strings
38-
│ &str
34+
LL │ …࿇࿈࿉࿊࿋࿌࿍࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun + " really fun!";
35+
┬───────────── ┯ ────────────── &str
36+
│ │
37+
│ `+` cannot be used to concatenate two `&str` strings
38+
&str
3939
4040
╰ note: string concatenation requires an owned `String` on the left
4141
help: create an owned `String` from a string reference

tests/ui/diagnostic-width/non-whitespace-trimming-unicode.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
error[E0308]: mismatched types
22
--> $DIR/non-whitespace-trimming-unicode.rs:4:415
33
|
4-
LL | ...♧♨♩♪♫♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚈⚉4"; let _: () = 42; let _: &str = "🦀☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓ ☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☰☱☲☳☴☵☶☷☸☹☺☻ ...
5-
| -- ^^ expected `()`, found integer
6-
| |
7-
| expected due to this
4+
LL | ...♧♨♩♪♫♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚈⚉4"; let _: () = 42; let _: &str = "🦀☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓ ☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☰☱☲...
5+
| -- ^^ expected `()`, found integer
6+
| |
7+
| expected due to this
88

99
error: aborting due to 1 previous error
1010

tests/ui/diagnostic-width/tabs-trimming.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
error[E0408]: variable `v` is not bound in all patterns
22
--> $DIR/tabs-trimming.rs:9:16
33
|
4-
LL | ... v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
5-
| - ^ ^ pattern doesn't bind `v`
6-
| | |
7-
| | pattern doesn't bind `v`
8-
| variable not in all patterns
4+
LL | ... v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
5+
| - ^ ^ pattern doesn't bind `v`
6+
| | |
7+
| | pattern doesn't bind `v`
8+
| variable not in all patterns
99

1010
error[E0381]: used binding `v` is possibly-uninitialized
1111
--> $DIR/tabs-trimming.rs:9:67
1212
|
13-
LL | ... v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
14-
| - ^ `v` used here but it is possibly-uninitialized
15-
| |
16-
| binding initialized here in some conditions
17-
| binding declared here but left uninitialized
13+
LL | ... v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
14+
| - ^ `v` used here but it is possibly-uninitialized
15+
| |
16+
| binding initialized here in some conditions
17+
| binding declared here but left uninitialized
1818

1919
error: aborting due to 2 previous errors
2020

tests/ui/macros/same-sequence-span.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ LL | $(= $z:tt)*
1515
= note: allowed there are: `=>`, `,` or `;`
1616

1717
error: `$x:expr` may be followed by `$y:tt`, which is not allowed for `expr` fragments
18-
--> $DIR/same-sequence-span.rs:19:1
18+
--> $DIR/same-sequence-span.rs:12:25
1919
|
20-
LL | | macro_rules! manual_foo {
21-
| |__________________________^not allowed after `expr` fragments
20+
LL | | // `proc_macro_sequence.rs`.
21+
| |_________________________^ not allowed after `expr` fragments
2222
...
2323
LL | proc_macro_sequence::make_foo!();
2424
| ^-------------------------------

0 commit comments

Comments
 (0)