Skip to content

Commit b4fe65c

Browse files
committed
Auto merge of #165708 - Muscraft:support-no-graphics, r=estebank
Add support for `annotate-snippets`'s `no-graphics` output format Tracking Issue: #165164 MCP: rust-lang/compiler-team#1045 This PR adds the initial support for `annotate-snippets`'s [`no-graphics` output format](https://docs.rs/annotate-snippets/latest/annotate_snippets/struct.Renderer.html#method.no_graphics). The `no-graphics` output format doesn't show source snippets or use any graphical decorations and is primarily designed for Text-To-Speech and Braille displays. The goal at this time is to get `no-graphics` in front of users so we can iterate on and improve the output. --- 🤖 LLM involvement: I used an LLM to review the commits before submitting r? @estebank
2 parents 6b05f82 + 6a4426f commit b4fe65c

64 files changed

Lines changed: 324 additions & 440 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Cargo.lock‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ dependencies = [
6464

6565
[[package]]
6666
name = "annotate-snippets"
67-
version = "0.12.16"
67+
version = "0.12.18"
6868
source = "registry+https://github.com/rust-lang/crates.io-index"
69-
checksum = "f211a51805bc641f3ad5b7664c77d2547af685cc33b4cd8d31964027a46f13f1"
69+
checksum = "0258346f92c78dbc5b336b9a5b27c64447aa10643bc64e651db2edb145361564"
7070
dependencies = [
7171
"anstyle",
7272
"memchr",
@@ -680,7 +680,7 @@ dependencies = [
680680
name = "clippy-dev"
681681
version = "0.0.1"
682682
dependencies = [
683-
"annotate-snippets 0.12.16",
683+
"annotate-snippets 0.12.18",
684684
"anstream 0.6.21",
685685
"chrono",
686686
"clap",
@@ -4041,7 +4041,7 @@ dependencies = [
40414041
name = "rustc_errors"
40424042
version = "0.0.0"
40434043
dependencies = [
4044-
"annotate-snippets 0.12.16",
4044+
"annotate-snippets 0.12.18",
40454045
"anstream 0.6.21",
40464046
"anstyle",
40474047
"derive_setters",
@@ -5179,7 +5179,7 @@ dependencies = [
51795179
name = "rustfmt-nightly"
51805180
version = "1.12.0"
51815181
dependencies = [
5182-
"annotate-snippets 0.12.16",
5182+
"annotate-snippets 0.12.18",
51835183
"anyhow",
51845184
"bytecount",
51855185
"cargo_metadata 0.23.1",

‎compiler/rustc_errors/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2024"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
annotate-snippets = { version = "0.12.16", features = ["simd"] }
8+
annotate-snippets = { version = "0.12.18", features = ["simd"] }
99
anstream = "0.6.20"
1010
anstyle = "1.0.13"
1111
derive_setters = "0.1.6"

‎compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct AnnotateSnippetEmitter {
4545
track_diagnostics: bool,
4646
terminal_url: TerminalUrl,
4747
theme: OutputTheme,
48+
no_graphics: bool,
4849
}
4950

5051
impl Debug for AnnotateSnippetEmitter {
@@ -60,6 +61,7 @@ impl Debug for AnnotateSnippetEmitter {
6061
track_diagnostics,
6162
terminal_url,
6263
theme,
64+
no_graphics,
6365
} = self;
6466

6567
f.debug_struct("AnnotateSnippetEmitter")
@@ -73,6 +75,7 @@ impl Debug for AnnotateSnippetEmitter {
7375
.field("track_diagnostics", track_diagnostics)
7476
.field("terminal_url", terminal_url)
7577
.field("theme", theme)
78+
.field("no_graphics", no_graphics)
7679
.finish()
7780
}
7881
}
@@ -153,6 +156,7 @@ impl AnnotateSnippetEmitter {
153156
track_diagnostics: false,
154157
terminal_url: TerminalUrl::No,
155158
theme: OutputTheme::Ascii,
159+
no_graphics: false,
156160
}
157161
}
158162

@@ -540,9 +544,10 @@ impl AnnotateSnippetEmitter {
540544
ColorChoice::Never => Renderer::plain(),
541545
}
542546
.term_width(width)
543-
.anonymized_line_numbers(self.ui_testing)
547+
.anonymized_snippet_line_numbers(self.ui_testing)
544548
.decor_style(decor_style)
545549
.short_message(self.short_message)
550+
.no_graphics(self.no_graphics)
546551
}
547552

548553
fn pre_style_msgs(&self, msgs: &[(DiagMessage, Style)], args: &DiagArgMap) -> String {

‎compiler/rustc_errors/src/emitter.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use crate::{
3333
/// Describes the way the content of the `rendered` field of the json output is generated
3434
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3535
pub struct HumanReadableErrorType {
36+
pub no_graphics: bool,
3637
pub short: bool,
3738
pub unicode: bool,
3839
}

‎compiler/rustc_errors/src/json.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ impl Diagnostic {
362362
.ui_testing(je.ui_testing)
363363
.ignored_directories_in_source_blocks(je.ignored_directories_in_source_blocks.clone())
364364
.theme(if je.json_rendered.unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
365+
.no_graphics(je.json_rendered.no_graphics)
365366
.emit_diagnostic(diag);
366367

367368
let buf = Arc::try_unwrap(buf.0).unwrap().into_inner().unwrap();

‎compiler/rustc_errors/src/json/tests.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
5151
Box::new(Shared { data: output.clone() }),
5252
Some(sm),
5353
true, // pretty
54-
HumanReadableErrorType { short: true, unicode: false },
54+
HumanReadableErrorType { no_graphics: false, short: true, unicode: false },
5555
ColorConfig::Never,
5656
);
5757

‎compiler/rustc_interface/src/tests.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ fn test_search_paths_tracking_hash_different_order() {
346346
let early_dcx = EarlyDiagCtxt::new(JSON);
347347
const JSON: ErrorOutputType = ErrorOutputType::Json {
348348
pretty: false,
349-
json_rendered: HumanReadableErrorType { short: false, unicode: false },
349+
json_rendered: HumanReadableErrorType { no_graphics: false, short: false, unicode: false },
350350
color_config: ColorConfig::Never,
351351
};
352352

‎compiler/rustc_parse/src/parser/tests.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ error: foo
309309
│
310310
2 │ fn foo() {
311311
│ ┏━━━━━━━━━━┛
312-
‡ ┃
312+
┆ ┇
313313
5 │ ┃ }
314314
╰╴┗━━━┛ test
315315
@@ -2126,7 +2126,7 @@ error: foo
21262126
5 │ │ 1
21272127
6 │ │ 2
21282128
7 │ │ 3
2129-
‡ │
2129+
┆ ┆
21302130
15 │ │ X2 Y2 Z2
21312131
16 │ │ X3 Y3 Z3
21322132
╰╴ └──────────┘ `Y` is a good letter too
@@ -2207,7 +2207,7 @@ error: foo
22072207
10 │ ┃│ 6
22082208
11 │ ┃│ X2 Y2 Z2
22092209
│ ┃└──────────┘ `Z` is a good letter too
2210-
‡ ┃
2210+
┆ ┇
22112211
15 │ ┃ 10
22122212
16 │ ┃ X3 Y3 Z3
22132213
╰╴┗━━━━━━━━┛ `Y` is a good letter

‎compiler/rustc_session/src/config.rs‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ pub enum ErrorOutputType {
887887
/// Output meant for the consumption of humans.
888888
#[default]
889889
HumanReadable {
890-
kind: HumanReadableErrorType = HumanReadableErrorType { short: false, unicode: false },
890+
kind: HumanReadableErrorType = HumanReadableErrorType { no_graphics: false, short: false, unicode: false },
891891
color_config: ColorConfig = ColorConfig::Auto,
892892
},
893893
/// Output that's consumed by other tools such as `rustfix` or the `RLS`.
@@ -2337,7 +2337,8 @@ impl JsonUnusedExterns {
23372337
/// The first value returned is how to render JSON diagnostics, and the second
23382338
/// is whether or not artifact notifications are enabled.
23392339
pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> JsonConfig {
2340-
let mut json_rendered = HumanReadableErrorType { short: false, unicode: false };
2340+
let mut json_rendered =
2341+
HumanReadableErrorType { no_graphics: false, short: false, unicode: false };
23412342
let mut json_color = ColorConfig::Never;
23422343
let mut json_artifact_notifications = false;
23432344
let mut json_unused_externs = JsonUnusedExterns::No;
@@ -2354,10 +2355,16 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
23542355
for sub_option in option.split(',') {
23552356
match sub_option {
23562357
"diagnostic-short" => {
2357-
json_rendered = HumanReadableErrorType { short: true, unicode: false };
2358+
json_rendered =
2359+
HumanReadableErrorType { no_graphics: false, short: true, unicode: false };
2360+
}
2361+
"diagnostic-no-graphics" => {
2362+
json_rendered =
2363+
HumanReadableErrorType { no_graphics: true, short: false, unicode: false };
23582364
}
23592365
"diagnostic-unicode" => {
2360-
json_rendered = HumanReadableErrorType { short: false, unicode: true };
2366+
json_rendered =
2367+
HumanReadableErrorType { no_graphics: false, short: false, unicode: true };
23612368
}
23622369
"diagnostic-rendered-ansi" => json_color = ColorConfig::Always,
23632370
"artifacts" => json_artifact_notifications = true,
@@ -2388,7 +2395,7 @@ pub fn parse_error_format(
23882395
json_color: ColorConfig,
23892396
json_rendered: HumanReadableErrorType,
23902397
) -> ErrorOutputType {
2391-
let default_kind = HumanReadableErrorType { short: false, unicode: false };
2398+
let default_kind = HumanReadableErrorType { no_graphics: false, short: false, unicode: false };
23922399
// We need the `opts_present` check because the driver will send us Matches
23932400
// with only stable options if no unstable options are used. Since error-format
23942401
// is unstable, it will not be present. We have to use `opts_present` not
@@ -2405,11 +2412,15 @@ pub fn parse_error_format(
24052412
ErrorOutputType::Json { pretty: true, json_rendered, color_config: json_color }
24062413
}
24072414
Some("short") => ErrorOutputType::HumanReadable {
2408-
kind: HumanReadableErrorType { short: true, unicode: false },
2415+
kind: HumanReadableErrorType { no_graphics: false, short: true, unicode: false },
2416+
color_config,
2417+
},
2418+
Some("human-no-graphics") => ErrorOutputType::HumanReadable {
2419+
kind: HumanReadableErrorType { no_graphics: true, short: false, unicode: false },
24092420
color_config,
24102421
},
24112422
Some("human-unicode") => ErrorOutputType::HumanReadable {
2412-
kind: HumanReadableErrorType { short: false, unicode: true },
2423+
kind: HumanReadableErrorType { no_graphics: false, short: false, unicode: true },
24132424
color_config,
24142425
},
24152426
Some(arg) => {
@@ -2418,8 +2429,8 @@ pub fn parse_error_format(
24182429
kind: default_kind,
24192430
});
24202431
early_dcx.early_fatal(format!(
2421-
"argument for `--error-format` must be `human`, `human-unicode`, \
2422-
`json`, `pretty-json` or `short` (instead was `{arg}`)"
2432+
"argument for `--error-format` must be `human`, `human-no-graphics`, \
2433+
`human-unicode`, `json`, `pretty-json` or `short` (instead was `{arg}`)"
24232434
))
24242435
}
24252436
}
@@ -2494,6 +2505,7 @@ fn check_error_format_stability(
24942505
let format = match format {
24952506
ErrorOutputType::Json { pretty: true, .. } => "pretty-json",
24962507
ErrorOutputType::HumanReadable { kind, .. } => match kind {
2508+
HumanReadableErrorType { no_graphics: true, .. } => "human-no-graphics",
24972509
HumanReadableErrorType { unicode: true, .. } => "human-unicode",
24982510
_ => return,
24992511
},

‎compiler/rustc_session/src/session.rs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ fn default_emitter(sopts: &config::Options, source_map: Arc<SourceMap>) -> Box<D
13101310

13111311
match sopts.error_format {
13121312
config::ErrorOutputType::HumanReadable { kind, color_config } => match kind {
1313-
HumanReadableErrorType { short, unicode } => {
1313+
HumanReadableErrorType { no_graphics, short, unicode } => {
13141314
let emitter = AnnotateSnippetEmitter::new(stderr_destination(color_config))
13151315
.sm(source_map)
13161316
.short_message(short)
@@ -1321,7 +1321,8 @@ fn default_emitter(sopts: &config::Options, source_map: Arc<SourceMap>) -> Box<D
13211321
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
13221322
.ignored_directories_in_source_blocks(
13231323
sopts.unstable_opts.ignore_directory_in_diagnostics_source_blocks.clone(),
1324-
);
1324+
)
1325+
.no_graphics(no_graphics);
13251326
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
13261327
}
13271328
},
@@ -1963,10 +1964,11 @@ impl EarlyDiagCtxt {
19631964
fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
19641965
let emitter: Box<DynEmitter> = match output {
19651966
config::ErrorOutputType::HumanReadable { kind, color_config } => match kind {
1966-
HumanReadableErrorType { short, unicode } => Box::new(
1967+
HumanReadableErrorType { no_graphics, short, unicode } => Box::new(
19671968
AnnotateSnippetEmitter::new(stderr_destination(color_config))
19681969
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
1969-
.short_message(short),
1970+
.short_message(short)
1971+
.no_graphics(no_graphics),
19701972
),
19711973
},
19721974
config::ErrorOutputType::Json { pretty, json_rendered, color_config } => {

0 commit comments

Comments
 (0)