Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ dependencies = [

[[package]]
name = "annotate-snippets"
version = "0.12.16"
version = "0.12.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f211a51805bc641f3ad5b7664c77d2547af685cc33b4cd8d31964027a46f13f1"
checksum = "b2a5b0a5ab8561c603f16c3b78c24a386b1f70e7fc1b1b1e8c15738828e4a176"
dependencies = [
"anstyle",
"memchr",
Expand Down Expand Up @@ -680,7 +680,7 @@ dependencies = [
name = "clippy-dev"
version = "0.0.1"
dependencies = [
"annotate-snippets 0.12.16",
"annotate-snippets 0.12.17",
"anstream 0.6.21",
"chrono",
"clap",
Expand Down Expand Up @@ -4041,7 +4041,7 @@ dependencies = [
name = "rustc_errors"
version = "0.0.0"
dependencies = [
"annotate-snippets 0.12.16",
"annotate-snippets 0.12.17",
"anstream 0.6.21",
"anstyle",
"derive_setters",
Expand Down Expand Up @@ -5179,7 +5179,7 @@ dependencies = [
name = "rustfmt-nightly"
version = "1.12.0"
dependencies = [
"annotate-snippets 0.12.16",
"annotate-snippets 0.12.17",
"anyhow",
"bytecount",
"cargo_metadata 0.23.1",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2024"

[dependencies]
# tidy-alphabetical-start
annotate-snippets = { version = "0.12.16", features = ["simd"] }
annotate-snippets = { version = "0.12.17", features = ["simd"] }
anstream = "0.6.20"
anstyle = "1.0.13"
derive_setters = "0.1.6"
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct AnnotateSnippetEmitter {
track_diagnostics: bool,
terminal_url: TerminalUrl,
theme: OutputTheme,
no_graphics: bool,
}

impl Debug for AnnotateSnippetEmitter {
Expand All @@ -60,6 +61,7 @@ impl Debug for AnnotateSnippetEmitter {
track_diagnostics,
terminal_url,
theme,
no_graphics,
} = self;

f.debug_struct("AnnotateSnippetEmitter")
Expand All @@ -73,6 +75,7 @@ impl Debug for AnnotateSnippetEmitter {
.field("track_diagnostics", track_diagnostics)
.field("terminal_url", terminal_url)
.field("theme", theme)
.field("no_graphics", no_graphics)
.finish()
}
}
Expand Down Expand Up @@ -153,6 +156,7 @@ impl AnnotateSnippetEmitter {
track_diagnostics: false,
terminal_url: TerminalUrl::No,
theme: OutputTheme::Ascii,
no_graphics: false,
}
}

Expand Down Expand Up @@ -540,9 +544,10 @@ impl AnnotateSnippetEmitter {
ColorChoice::Never => Renderer::plain(),
}
.term_width(width)
.anonymized_line_numbers(self.ui_testing)
.anonymized_snippet_line_numbers(self.ui_testing)
.decor_style(decor_style)
.short_message(self.short_message)
.no_graphics(self.no_graphics)
}

fn pre_style_msgs(&self, msgs: &[(DiagMessage, Style)], args: &DiagArgMap) -> String {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::{
/// Describes the way the content of the `rendered` field of the json output is generated
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct HumanReadableErrorType {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocker. We should be moving towards an enum, I think.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should move to an enum, and I tried to do so, but I ran into issues discerning what should be variants vs. options e.g., is short its own rendering format (variant), or is it an option on graphics/no-graphics?

@estebank estebank Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that (at least eventually) we likely want to fully enumerate all of the cases (so short would be its own thing). The only one that is orthogonal is color, IMO. To be clear, I don't mind not doing that in this PR!

pub no_graphics: bool,
pub short: bool,
pub unicode: bool,
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ impl Diagnostic {
.ui_testing(je.ui_testing)
.ignored_directories_in_source_blocks(je.ignored_directories_in_source_blocks.clone())
.theme(if je.json_rendered.unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
.no_graphics(je.json_rendered.no_graphics)
.emit_diagnostic(diag);

let buf = Arc::try_unwrap(buf.0).unwrap().into_inner().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/json/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
Box::new(Shared { data: output.clone() }),
Some(sm),
true, // pretty
HumanReadableErrorType { short: true, unicode: false },
HumanReadableErrorType { no_graphics: false, short: true, unicode: false },
ColorConfig::Never,
);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ fn test_search_paths_tracking_hash_different_order() {
let early_dcx = EarlyDiagCtxt::new(JSON);
const JSON: ErrorOutputType = ErrorOutputType::Json {
pretty: false,
json_rendered: HumanReadableErrorType { short: false, unicode: false },
json_rendered: HumanReadableErrorType { no_graphics: false, short: false, unicode: false },
color_config: ColorConfig::Never,
};

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_parse/src/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ error: foo
│
2 │ fn foo() {
│ ┏━━━━━━━━━━┛
‡ ┃
┆ ┇
5 │ ┃ }
╰╴┗━━━┛ test

Expand Down Expand Up @@ -2126,7 +2126,7 @@ error: foo
5 │ │ 1
6 │ │ 2
7 │ │ 3
‡ │
┆ ┆
15 │ │ X2 Y2 Z2
16 │ │ X3 Y3 Z3
╰╴ └──────────┘ `Y` is a good letter too
Expand Down Expand Up @@ -2207,7 +2207,7 @@ error: foo
10 │ ┃│ 6
11 │ ┃│ X2 Y2 Z2
│ ┃└──────────┘ `Z` is a good letter too
‡ ┃
┆ ┇
15 │ ┃ 10
16 │ ┃ X3 Y3 Z3
╰╴┗━━━━━━━━┛ `Y` is a good letter
Expand Down
30 changes: 21 additions & 9 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ pub enum ErrorOutputType {
/// Output meant for the consumption of humans.
#[default]
HumanReadable {
kind: HumanReadableErrorType = HumanReadableErrorType { short: false, unicode: false },
kind: HumanReadableErrorType = HumanReadableErrorType { no_graphics: false, short: false, unicode: false },
color_config: ColorConfig = ColorConfig::Auto,
},
/// Output that's consumed by other tools such as `rustfix` or the `RLS`.
Expand Down Expand Up @@ -2337,7 +2337,8 @@ impl JsonUnusedExterns {
/// The first value returned is how to render JSON diagnostics, and the second
/// is whether or not artifact notifications are enabled.
pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> JsonConfig {
let mut json_rendered = HumanReadableErrorType { short: false, unicode: false };
let mut json_rendered =
HumanReadableErrorType { no_graphics: false, short: false, unicode: false };
let mut json_color = ColorConfig::Never;
let mut json_artifact_notifications = false;
let mut json_unused_externs = JsonUnusedExterns::No;
Expand All @@ -2354,10 +2355,16 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
for sub_option in option.split(',') {
match sub_option {
"diagnostic-short" => {
json_rendered = HumanReadableErrorType { short: true, unicode: false };
json_rendered =
HumanReadableErrorType { no_graphics: false, short: true, unicode: false };
}
"diagnostic-no-graphics" => {
json_rendered =
HumanReadableErrorType { no_graphics: true, short: false, unicode: false };
}
"diagnostic-unicode" => {
json_rendered = HumanReadableErrorType { short: false, unicode: true };
json_rendered =
HumanReadableErrorType { no_graphics: false, short: false, unicode: true };
}
"diagnostic-rendered-ansi" => json_color = ColorConfig::Always,
"artifacts" => json_artifact_notifications = true,
Expand Down Expand Up @@ -2388,7 +2395,7 @@ pub fn parse_error_format(
json_color: ColorConfig,
json_rendered: HumanReadableErrorType,
) -> ErrorOutputType {
let default_kind = HumanReadableErrorType { short: false, unicode: false };
let default_kind = HumanReadableErrorType { no_graphics: false, short: false, unicode: false };
// We need the `opts_present` check because the driver will send us Matches
// with only stable options if no unstable options are used. Since error-format
// is unstable, it will not be present. We have to use `opts_present` not
Expand All @@ -2405,11 +2412,15 @@ pub fn parse_error_format(
ErrorOutputType::Json { pretty: true, json_rendered, color_config: json_color }
}
Some("short") => ErrorOutputType::HumanReadable {
kind: HumanReadableErrorType { short: true, unicode: false },
kind: HumanReadableErrorType { no_graphics: false, short: true, unicode: false },
color_config,
},
Some("human-no-graphics") => ErrorOutputType::HumanReadable {
kind: HumanReadableErrorType { no_graphics: true, short: false, unicode: false },
color_config,
},
Some("human-unicode") => ErrorOutputType::HumanReadable {
kind: HumanReadableErrorType { short: false, unicode: true },
kind: HumanReadableErrorType { no_graphics: false, short: false, unicode: true },
color_config,
},
Some(arg) => {
Expand All @@ -2418,8 +2429,8 @@ pub fn parse_error_format(
kind: default_kind,
});
early_dcx.early_fatal(format!(
"argument for `--error-format` must be `human`, `human-unicode`, \
`json`, `pretty-json` or `short` (instead was `{arg}`)"
"argument for `--error-format` must be `human`, `human-no-graphics`, \
`human-unicode`, `json`, `pretty-json` or `short` (instead was `{arg}`)"
))
}
}
Expand Down Expand Up @@ -2494,6 +2505,7 @@ fn check_error_format_stability(
let format = match format {
ErrorOutputType::Json { pretty: true, .. } => "pretty-json",
ErrorOutputType::HumanReadable { kind, .. } => match kind {
HumanReadableErrorType { no_graphics: true, .. } => "human-no-graphics",
HumanReadableErrorType { unicode: true, .. } => "human-unicode",
_ => return,
},
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ fn default_emitter(sopts: &config::Options, source_map: Arc<SourceMap>) -> Box<D

match sopts.error_format {
config::ErrorOutputType::HumanReadable { kind, color_config } => match kind {
HumanReadableErrorType { short, unicode } => {
HumanReadableErrorType { no_graphics, short, unicode } => {
let emitter = AnnotateSnippetEmitter::new(stderr_destination(color_config))
.sm(source_map)
.short_message(short)
Expand All @@ -1321,7 +1321,8 @@ fn default_emitter(sopts: &config::Options, source_map: Arc<SourceMap>) -> Box<D
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
.ignored_directories_in_source_blocks(
sopts.unstable_opts.ignore_directory_in_diagnostics_source_blocks.clone(),
);
)
.no_graphics(no_graphics);
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
}
},
Expand Down Expand Up @@ -1963,10 +1964,11 @@ impl EarlyDiagCtxt {
fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
let emitter: Box<DynEmitter> = match output {
config::ErrorOutputType::HumanReadable { kind, color_config } => match kind {
HumanReadableErrorType { short, unicode } => Box::new(
HumanReadableErrorType { no_graphics, short, unicode } => Box::new(
AnnotateSnippetEmitter::new(stderr_destination(color_config))
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
.short_message(short),
.short_message(short)
.no_graphics(no_graphics),
),
},
config::ErrorOutputType::Json { pretty, json_rendered, color_config } => {
Expand Down
5 changes: 3 additions & 2 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,15 @@ pub(crate) fn new_dcx(
) -> rustc_errors::DiagCtxt {
let emitter: Box<DynEmitter> = match error_format {
ErrorOutputType::HumanReadable { kind, color_config } => match kind {
HumanReadableErrorType { short, unicode } => Box::new(
HumanReadableErrorType { no_graphics, short, unicode } => Box::new(
AnnotateSnippetEmitter::new(stderr_destination(color_config))
.sm(source_map.map(|sm| sm as _))
.short_message(short)
.diagnostic_width(diagnostic_width)
.track_diagnostics(unstable_opts.track_diagnostics)
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
.ui_testing(unstable_opts.ui_testing),
.ui_testing(unstable_opts.ui_testing)
.no_graphics(no_graphics),
),
},
ErrorOutputType::Json { pretty, json_rendered, color_config } => {
Expand Down
7 changes: 5 additions & 2 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,9 +648,12 @@ fn run_test(
},
]);
if let ErrorOutputType::HumanReadable { kind, color_config } = rustdoc_options.error_format {
let short = kind.short();
let unicode = kind == HumanReadableErrorType { unicode: true, short };
let HumanReadableErrorType { no_graphics, short, unicode } = kind;

if no_graphics {
compiler_args
.extend_from_slice(&["--error-format".to_owned(), "human-no-graphics".to_owned()]);
}
if short {
compiler_args.extend_from_slice(&["--error-format".to_owned(), "short".to_owned()]);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/jobserver-error/cannot_open_fd.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
warning: failed to connect to jobserver from environment variable `MAKEFLAGS="--jobserver-auth=1000,1000"`: cannot open file descriptor 1000 from the jobserver environment variable value: Bad file descriptor (os error 9)
|
= note: the build environment is likely misconfigured
|
= note: the build environment is likely misconfigured

error: no input filename given

Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/jobserver-error/not_a_pipe.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning: failed to connect to jobserver from environment variable `MAKEFLAGS="--jobserver-auth=3,3"`: file descriptor 3 from the jobserver environment variable value is not a pipe
|
= note: the build environment is likely misconfigured
|
= note: the build environment is likely misconfigured

4 changes: 2 additions & 2 deletions tests/run-make/linker-warning/deny-linker-lint.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
error: linker stderr: bar
|
= note: requested on the command line with `-D linker-messages`
|
= note: requested on the command line with `-D linker-messages`

error: aborting due to 1 previous error

6 changes: 3 additions & 3 deletions tests/run-make/linker-warning/deny-warnings.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
warning: linker stderr: bar
|
= note: requested on the command line with `-W linker-messages`
= note: the `linker_messages` lint ignores `-D warnings`
|
= note: requested on the command line with `-W linker-messages`
= note: the `linker_messages` lint ignores `-D warnings`

warning: 1 warning emitted

10 changes: 5 additions & 5 deletions tests/run-make/linker-warning/short-error.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
error: linking with `./fake-linker` failed: exit status: 1
|
= note: "./fake-linker" "-m64" "/symbols.o" "<2 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/build-root/test/run-make/linker-warning/rmake_out/{libfoo,libbar}.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,libcfg_if-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/build-root/test/run-make/linker-warning/rmake_out" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "main" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "run_make_error"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: error: baz
|
= note: "./fake-linker" "-m64" "/symbols.o" "<2 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/build-root/test/run-make/linker-warning/rmake_out/{libfoo,libbar}.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,libcfg_if-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/build-root/test/run-make/linker-warning/rmake_out" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "main" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "run_make_error"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: error: baz


error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: invalid `--check-cfg` argument: `---
---
cfg(key)`
|
= note: expected `cfg(name, values("value1", "value2", ... "valueN"))`
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details
|
= note: expected `cfg(name, values("value1", "value2", ... "valueN"))`
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details

6 changes: 3 additions & 3 deletions tests/run-make/multiline-args-value/check-cfg-shebang.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
error: invalid `--check-cfg` argument: `#!/usr/bin/shebang
cfg(key)`
|
= note: expected `cfg(name, values("value1", "value2", ... "valueN"))`
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details
|
= note: expected `cfg(name, values("value1", "value2", ... "valueN"))`
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unknown print request: `xxx`
|
= help: valid print requests are: `all-target-specs-json`, `cfg`, `check-cfg`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `target-spec-json-schema`, `wasm-proc-macro-tuple`
|
= help: valid print requests are: `all-target-specs-json`, `cfg`, `check-cfg`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `target-spec-json-schema`, `wasm-proc-macro-tuple`

8 changes: 4 additions & 4 deletions tests/ui/bootstrap/rustc_bootstrap.force_stable.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: the option `Z` is only accepted on the nightly compiler

error: 1 nightly option was parsed
|
= help: consider switching to a nightly toolchain: `rustup default nightly`
= note: selecting a toolchain with `+toolchain` arguments require a rustup proxy; see <https://rust-lang.github.io/rustup/concepts/index.html>
= note: for more information about Rust's stability policy, see <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html#unstable-features>
|
= help: consider switching to a nightly toolchain: `rustup default nightly`
= note: selecting a toolchain with `+toolchain` arguments require a rustup proxy; see <https://rust-lang.github.io/rustup/concepts/index.html>
= note: for more information about Rust's stability policy, see <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html#unstable-features>

Loading
Loading