about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-01-05 14:11:12 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-01-05 14:37:06 +1100
commit884322389759a9a9563e492d8bbd96b83c27c2de (patch)
tree5ff094b55265ebd6a8cfd21e4d90dcce5977e2f4 /compiler
parentf5a09a9e1d162793d16b53cd6ad266a37e11d800 (diff)
downloadrust-884322389759a9a9563e492d8bbd96b83c27c2de.tar.gz
rust-884322389759a9a9563e492d8bbd96b83c27c2de.zip
Change printing of "`--error-format` is unstable" errors.
Currently for these two errors we go to the effort of switching to a
standard JSON emitter, for no obvious reason, and unlike any other
errors. This behaviour was added for `pretty-json` in #45737, and then
`human-annotate-rs` copied it some time later when it was added.

This commit changes things to just using the requested emitter, which is
simpler and consistent with other errors.

Old output:
```
$ rustc --error-format pretty-json
{"$message_type":"diagnostic","message":"`--error-format=pretty-json` is unstable","code":null,"level":"error","spans":[],"children":[],"rendered":"error: `--error-format=pretty-json` is unstable\n\n"}

$ rustc --error-format human-annotate-rs
{"$message_type":"diagnostic","message":"`--error-format=human-annotate-rs` is unstable","code":null,"level":"error","spans":[],"children":[],"rendered":"error: `--error-format=human-annotate-rs` is unstable\n\n"}
```

New output:
```
$ rustc --error-format pretty-json
{
  "$message_type": "diagnostic",
  "message": "`--error-format=pretty-json` is unstable",
  "code": null,
  "level": "error",
  "spans": [],
  "children": [],
  "rendered": "error: `--error-format=pretty-json` is unstable\n\n"
}

$ rustc --error-format human-annotate-rs
error: `--error-format=human-annotate-rs` is unstable
```
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_session/src/config.rs13
1 files changed, 2 insertions, 11 deletions
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs
index 89508c77639..c04c67dd398 100644
--- a/compiler/rustc_session/src/config.rs
+++ b/compiler/rustc_session/src/config.rs
@@ -2051,23 +2051,14 @@ fn check_error_format_stability(
     early_dcx: &mut EarlyDiagCtxt,
     unstable_opts: &UnstableOptions,
     error_format: ErrorOutputType,
-    json_rendered: HumanReadableErrorType,
 ) {
     if !unstable_opts.unstable_options {
-        if let ErrorOutputType::Json { pretty: true, json_rendered } = error_format {
-            early_dcx.abort_if_error_and_set_error_format(ErrorOutputType::Json {
-                pretty: false,
-                json_rendered,
-            });
+        if let ErrorOutputType::Json { pretty: true, .. } = error_format {
             early_dcx.early_fatal("`--error-format=pretty-json` is unstable");
         }
         if let ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateSnippet(_)) =
             error_format
         {
-            early_dcx.abort_if_error_and_set_error_format(ErrorOutputType::Json {
-                pretty: false,
-                json_rendered,
-            });
             early_dcx.early_fatal("`--error-format=human-annotate-rs` is unstable");
         }
     }
@@ -2665,7 +2656,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
     let mut unstable_opts = UnstableOptions::build(early_dcx, matches);
     let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(early_dcx, matches);
 
-    check_error_format_stability(early_dcx, &unstable_opts, error_format, json_rendered);
+    check_error_format_stability(early_dcx, &unstable_opts, error_format);
 
     if !unstable_opts.unstable_options && json_unused_externs.is_enabled() {
         early_dcx.early_fatal(