feat: Always use annotate-snippets for Unicode output
This commit is contained in:
parent
a75bd03fb9
commit
4748d92a95
9 changed files with 54 additions and 78 deletions
|
|
@ -48,8 +48,7 @@ const DEFAULT_COLUMN_WIDTH: usize = 140;
|
|||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum HumanReadableErrorType {
|
||||
Default,
|
||||
Unicode,
|
||||
AnnotateSnippet,
|
||||
AnnotateSnippet { unicode: bool },
|
||||
Short,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -379,7 +379,7 @@ impl Diagnostic {
|
|||
choice => choice,
|
||||
},
|
||||
);
|
||||
if let HumanReadableErrorType::AnnotateSnippet = je.json_rendered {
|
||||
if let HumanReadableErrorType::AnnotateSnippet { unicode } = je.json_rendered {
|
||||
AnnotateSnippetEmitter::new(dst, je.translator.clone())
|
||||
.short_message(short)
|
||||
.sm(je.sm.clone())
|
||||
|
|
@ -391,12 +391,8 @@ impl Diagnostic {
|
|||
.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);
|
||||
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
|
||||
.emit_diagnostic(diag, registry)
|
||||
} else {
|
||||
HumanEmitter::new(dst, je.translator.clone())
|
||||
.short_message(short)
|
||||
|
|
@ -409,12 +405,8 @@ impl Diagnostic {
|
|||
.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);
|
||||
.theme(OutputTheme::Ascii)
|
||||
.emit_diagnostic(diag, registry)
|
||||
}
|
||||
|
||||
let buf = Arc::try_unwrap(buf.0).unwrap().into_inner().unwrap();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#![allow(rustc::symbol_intern_string_literal)]
|
||||
|
||||
use std::assert_matches::assert_matches;
|
||||
use std::io::prelude::*;
|
||||
use std::iter::Peekable;
|
||||
|
|
@ -12,6 +11,7 @@ use rustc_ast::token::{self, Delimiter, Token};
|
|||
use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
|
||||
use rustc_ast::{self as ast, PatKind, visit};
|
||||
use rustc_ast_pretty::pprust::item_to_string;
|
||||
use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
|
||||
use rustc_errors::emitter::{HumanEmitter, OutputTheme};
|
||||
use rustc_errors::translation::Translator;
|
||||
use rustc_errors::{AutoStream, DiagCtxt, MultiSpan, PResult};
|
||||
|
|
@ -43,12 +43,22 @@ fn create_test_handler(theme: OutputTheme) -> (DiagCtxt, Arc<SourceMap>, Arc<Mut
|
|||
let output = Arc::new(Mutex::new(Vec::new()));
|
||||
let source_map = Arc::new(SourceMap::new(FilePathMapping::empty()));
|
||||
let translator = Translator::with_fallback_bundle(vec![crate::DEFAULT_LOCALE_RESOURCE], false);
|
||||
let mut emitter =
|
||||
HumanEmitter::new(AutoStream::never(Box::new(Shared { data: output.clone() })), translator)
|
||||
.sm(Some(source_map.clone()))
|
||||
.diagnostic_width(Some(140));
|
||||
emitter = emitter.theme(theme);
|
||||
let dcx = DiagCtxt::new(Box::new(emitter));
|
||||
let shared: Box<dyn Write + Send> = Box::new(Shared { data: output.clone() });
|
||||
let auto_stream = AutoStream::never(shared);
|
||||
let dcx = DiagCtxt::new(match theme {
|
||||
OutputTheme::Ascii => Box::new(
|
||||
HumanEmitter::new(auto_stream, translator)
|
||||
.sm(Some(source_map.clone()))
|
||||
.diagnostic_width(Some(140))
|
||||
.theme(theme),
|
||||
),
|
||||
OutputTheme::Unicode => Box::new(
|
||||
AnnotateSnippetEmitter::new(auto_stream, translator)
|
||||
.sm(Some(source_map.clone()))
|
||||
.diagnostic_width(Some(140))
|
||||
.theme(theme),
|
||||
),
|
||||
});
|
||||
(dcx, source_map, output)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2060,7 +2060,7 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
|
|||
match sub_option {
|
||||
"diagnostic-short" => json_rendered = HumanReadableErrorType::Short,
|
||||
"diagnostic-unicode" => {
|
||||
json_rendered = HumanReadableErrorType::Unicode;
|
||||
json_rendered = HumanReadableErrorType::AnnotateSnippet { unicode: true };
|
||||
}
|
||||
"diagnostic-rendered-ansi" => json_color = ColorConfig::Always,
|
||||
"artifacts" => json_artifact_notifications = true,
|
||||
|
|
@ -2099,7 +2099,7 @@ pub fn parse_error_format(
|
|||
match matches.opt_str("error-format").as_deref() {
|
||||
None | Some("human") => ErrorOutputType::HumanReadable { color_config, .. },
|
||||
Some("human-annotate-rs") => ErrorOutputType::HumanReadable {
|
||||
kind: HumanReadableErrorType::AnnotateSnippet,
|
||||
kind: HumanReadableErrorType::AnnotateSnippet { unicode: false },
|
||||
color_config,
|
||||
},
|
||||
Some("json") => {
|
||||
|
|
@ -2112,7 +2112,7 @@ pub fn parse_error_format(
|
|||
ErrorOutputType::HumanReadable { kind: HumanReadableErrorType::Short, color_config }
|
||||
}
|
||||
Some("human-unicode") => ErrorOutputType::HumanReadable {
|
||||
kind: HumanReadableErrorType::Unicode,
|
||||
kind: HumanReadableErrorType::AnnotateSnippet { unicode: true },
|
||||
color_config,
|
||||
},
|
||||
Some(arg) => {
|
||||
|
|
@ -2180,8 +2180,8 @@ fn check_error_format_stability(
|
|||
let format = match format {
|
||||
ErrorOutputType::Json { pretty: true, .. } => "pretty-json",
|
||||
ErrorOutputType::HumanReadable { kind, .. } => match kind {
|
||||
HumanReadableErrorType::AnnotateSnippet => "human-annotate-rs",
|
||||
HumanReadableErrorType::Unicode => "human-unicode",
|
||||
HumanReadableErrorType::AnnotateSnippet { unicode: false } => "human-annotate-rs",
|
||||
HumanReadableErrorType::AnnotateSnippet { unicode: true } => "human-unicode",
|
||||
_ => return,
|
||||
},
|
||||
_ => return,
|
||||
|
|
|
|||
|
|
@ -952,8 +952,7 @@ fn default_emitter(
|
|||
match sopts.error_format {
|
||||
config::ErrorOutputType::HumanReadable { kind, color_config } => {
|
||||
let short = kind.short();
|
||||
|
||||
if let HumanReadableErrorType::AnnotateSnippet = kind {
|
||||
if let HumanReadableErrorType::AnnotateSnippet { unicode } = kind {
|
||||
let emitter =
|
||||
AnnotateSnippetEmitter::new(stderr_destination(color_config), translator)
|
||||
.sm(source_map)
|
||||
|
|
@ -962,11 +961,7 @@ fn default_emitter(
|
|||
.macro_backtrace(macro_backtrace)
|
||||
.track_diagnostics(track_diagnostics)
|
||||
.terminal_url(terminal_url)
|
||||
.theme(if let HumanReadableErrorType::Unicode = kind {
|
||||
OutputTheme::Unicode
|
||||
} else {
|
||||
OutputTheme::Ascii
|
||||
})
|
||||
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
|
||||
.ignored_directories_in_source_blocks(
|
||||
sopts
|
||||
.unstable_opts
|
||||
|
|
@ -982,11 +977,7 @@ fn default_emitter(
|
|||
.macro_backtrace(macro_backtrace)
|
||||
.track_diagnostics(track_diagnostics)
|
||||
.terminal_url(terminal_url)
|
||||
.theme(if let HumanReadableErrorType::Unicode = kind {
|
||||
OutputTheme::Unicode
|
||||
} else {
|
||||
OutputTheme::Ascii
|
||||
})
|
||||
.theme(OutputTheme::Ascii)
|
||||
.ignored_directories_in_source_blocks(
|
||||
sopts.unstable_opts.ignore_directory_in_diagnostics_source_blocks.clone(),
|
||||
);
|
||||
|
|
@ -1501,24 +1492,16 @@ fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
|
|||
let emitter: Box<DynEmitter> = match output {
|
||||
config::ErrorOutputType::HumanReadable { kind, color_config } => {
|
||||
let short = kind.short();
|
||||
if let HumanReadableErrorType::AnnotateSnippet = kind {
|
||||
if let HumanReadableErrorType::AnnotateSnippet { unicode } = kind {
|
||||
Box::new(
|
||||
AnnotateSnippetEmitter::new(stderr_destination(color_config), translator)
|
||||
.theme(if let HumanReadableErrorType::Unicode = kind {
|
||||
OutputTheme::Unicode
|
||||
} else {
|
||||
OutputTheme::Ascii
|
||||
})
|
||||
.theme(if unicode { 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
|
||||
})
|
||||
.theme(OutputTheme::Ascii)
|
||||
.short_message(short),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,18 +155,14 @@ pub(crate) fn new_dcx(
|
|||
let emitter: Box<DynEmitter> = match error_format {
|
||||
ErrorOutputType::HumanReadable { kind, color_config } => {
|
||||
let short = kind.short();
|
||||
if let HumanReadableErrorType::AnnotateSnippet = kind {
|
||||
if let HumanReadableErrorType::AnnotateSnippet { unicode } = 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
|
||||
})
|
||||
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
|
||||
.ui_testing(unstable_opts.ui_testing),
|
||||
)
|
||||
} else {
|
||||
|
|
@ -176,11 +172,7 @@ pub(crate) fn new_dcx(
|
|||
.short_message(short)
|
||||
.diagnostic_width(diagnostic_width)
|
||||
.track_diagnostics(unstable_opts.track_diagnostics)
|
||||
.theme(if let HumanReadableErrorType::Unicode = kind {
|
||||
OutputTheme::Unicode
|
||||
} else {
|
||||
OutputTheme::Ascii
|
||||
})
|
||||
.theme(OutputTheme::Ascii)
|
||||
.ui_testing(unstable_opts.ui_testing),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -600,7 +600,7 @@ fn run_test(
|
|||
]);
|
||||
if let ErrorOutputType::HumanReadable { kind, color_config } = rustdoc_options.error_format {
|
||||
let short = kind.short();
|
||||
let unicode = kind == HumanReadableErrorType::Unicode;
|
||||
let unicode = kind == HumanReadableErrorType::AnnotateSnippet { unicode: true };
|
||||
|
||||
if short {
|
||||
compiler_args.extend_from_slice(&["--error-format".to_owned(), "short".to_owned()]);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
error[E0369]: cannot add `&str` to `&str`
|
||||
╭▸ $DIR/non-1-width-unicode-multiline-label.rs:8:237
|
||||
│
|
||||
LL │ …👧👦👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
|
||||
│ ┬───────────── ┯ ────────────── &str
|
||||
│ │ │
|
||||
│ │ `+` cannot be used to concatenate two `&str` strings
|
||||
│ &str
|
||||
LL │ … 👧👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
|
||||
│ ┬───────────── ┯ ────────────── &str
|
||||
│ │ │
|
||||
│ │ `+` cannot be used to concatenate two `&str` strings
|
||||
│ &str
|
||||
│
|
||||
╰ note: string concatenation requires an owned `String` on the left
|
||||
help: create an owned `String` from a string reference
|
||||
|
|
@ -16,11 +16,11 @@ LL │ let _ = "👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧
|
|||
error[E0369]: cannot add `&str` to `&str`
|
||||
╭▸ $DIR/non-1-width-unicode-multiline-label.rs:10:384
|
||||
│
|
||||
LL │ …👨👩👧👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
|
||||
│ ┬───────────── ┯ ────────────── &str
|
||||
│ │ │
|
||||
│ │ `+` cannot be used to concatenate two `&str` strings
|
||||
│ &str
|
||||
LL │ … 👧👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
|
||||
│ ┬───────────── ┯ ────────────── &str
|
||||
│ │ │
|
||||
│ │ `+` cannot be used to concatenate two `&str` strings
|
||||
│ &str
|
||||
│
|
||||
╰ note: string concatenation requires an owned `String` on the left
|
||||
help: create an owned `String` from a string reference
|
||||
|
|
@ -31,11 +31,11 @@ LL │ let _ = "👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧
|
|||
error[E0369]: cannot add `&str` to `&str`
|
||||
╭▸ $DIR/non-1-width-unicode-multiline-label.rs:12:260
|
||||
│
|
||||
LL │ …࿅࿆࿇࿈࿉࿊࿋࿌࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun + " really fun!";
|
||||
│ ┬───────────── ┯ ────────────── &str
|
||||
│ │ │
|
||||
│ │ `+` cannot be used to concatenate two `&str` strings
|
||||
│ &str
|
||||
LL │ …࿄࿅࿆࿇࿈࿉࿊࿋࿌࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun + " really fun!";
|
||||
│ ┬───────────── ┯ ────────────── &str
|
||||
│ │ │
|
||||
│ │ `+` cannot be used to concatenate two `&str` strings
|
||||
│ &str
|
||||
│
|
||||
╰ note: string concatenation requires an owned `String` on the left
|
||||
help: create an owned `String` from a string reference
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
</tspan>
|
||||
<tspan x="10px" y="316px"><tspan class="fg-bright-blue bold">LL</tspan><tspan> </tspan><tspan class="fg-bright-blue bold">│</tspan><tspan> </tspan><tspan class="fg-bright-blue bold">│</tspan><tspan> )>>) {}</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="334px"><tspan> </tspan><tspan class="fg-bright-blue bold">╰╴</tspan><tspan class="fg-bright-blue bold">└───┘</tspan>
|
||||
<tspan x="10px" y="334px"><tspan> </tspan><tspan class="fg-bright-blue bold">╰╴└───┘</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="352px">
|
||||
</tspan>
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
Loading…
Add table
Add a link
Reference in a new issue