Repository: rust
Issue: Passing `--error-format=json` does not impact panic message format
Labels: A-diagnostics,T-compiler,D-diagnostic-infra

### Code

```Rust
//! Code extracted from #106874 that triggers a panic with rustc.
//! Run with:
//! 
//! rustc ice.rs --error-format=json
//! 
use std::marker::PhantomData;
use std::rc::Rc;

pub fn func<V, F: Fn(&mut V)>(f: F) -> A<impl X> {
    A(B(C::new(D::new(move |st| f(st)))))
}

trait X {}
trait Y {
    type V;
}

struct A<T>(T);

struct B<T>(Rc<T>);
impl<T> X for B<T> {}

struct C<T: Y>(T::V);
impl<T: Y> C<T> {
    fn new(_: T) -> Rc<Self> {
        todo!()
    }
}
struct D<V, F>(F, PhantomData<fn(&mut V)>);

impl<V, F> D<V, F> {
    fn new(_: F) -> Self {
        todo!()
    }
}
impl<V, F: Fn(&mut V)> Y for D<V, F> {
    type V = V;
}
```


### Current output

```Shell
{"message":"`main` function not found in crate `ice`","code":{"code":"E0601","explanation":"No `main` function was found in a binary crate.\n\nTo fix this error, add a `main` function:\n\n\nfn main() {\n    // Your program will start here.\n    println!(\"Hello world!\");\n}\n```\n\nIf you don't know the basics of Rust, you can look at the\n[Rust Book][rust-book] to get started.\n\n[rust-book]: https://doc.rust-lang.org/book/\n"},"level":"error","spans":[{"file_name":"ice.rs","byte_start":508,"byte_end":508,"line_start":33,"line_end":33,"column_start":2,"column_end":2,"is_primary":true,"text":[{"text":"}","highlight_start":2,"highlight_end":2}],"label":"consider adding a `main` function to `ice.rs`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0601]: `main` function not found in crate `ice`\n  --> ice.rs:33:2\n   |\n33 | }\n   |  ^ consider adding a `main` function to `ice.rs`\n\n"}
thread 'rustc' panicked at 'no entry found for key', compiler/rustc_borrowck/src/region_infer/mod.rs:2195:9
stack backtrace:
   0:     0x7f2cce61d937 - std::backtrace_rs::backtrace::libunwind::trace::h82026d2dcd89baea
                               at /rust/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   .... (redacted)


error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.67.0-dev running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `func`
#1 [type_of] computing type of `func::{opaque#0}`
#2 [check_mod_item_types] checking item types in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
{"message":"For more information about this error, try `rustc --explain E0601`.","code":null,"level":"failure-note","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0601`.\n"}
```


### Desired output

```Shell
{"message":"`main` function not found in crate `ice`","code":{"code":"E0601","explanation":"No `main` function was found in a binary crate.\n\nTo fix this error, add a `main` function:\n\n\nfn main() {\n    // Your program will start here.\n    println!(\"Hello world!\");\n}\n```\n\nIf you don't know the basics of Rust, you can look at the\n[Rust Book][rust-book] to get started.\n\n[rust-book]: https://doc.rust-lang.org/book/\n"},"level":"error","spans":[{"file_name":"ice.rs","byte_start":508,"byte_end":508,"line_start":33,"line_end":33,"column_start":2,"column_end":2,"is_primary":true,"text":[{"text":"}","highlight_start":2,"highlight_end":2}],"label":"consider adding a `main` function to `ice.rs`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0601]: `main` function not found in crate `ice`\n  --> ice.rs:33:2\n   |\n33 | }\n   |  ^ consider adding a `main` function to `ice.rs`\n\n"}
{"message":"thread 'rustc' panicked at 'no entry found for key', compiler/rustc_borrowck/src/region_infer/mod.rs:2195:9","code":null,"level":"error: internal compiler error","spans":[],"children":[],"rendered":"error: internal compiler error: thread 'rustc' panicked at 'no entry found for key', compiler/rustc_borrowck/src/region_infer/mod.rs:2196:9\n\n"}
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
{"message":"For more information about this error, try `rustc --explain E0601`.","code":null,"level":"failure-note","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0601`.\n"}
```


### Rationale and extra context

The panic message should be treated as a ICE message, and be its format should match whatever format was requested by the user. Users that request `json` format want to programmatically retrieve the compilation status, but they could be missing an important message such as the compiler crashing.

### Other cases

_No response_

### Anything else?

_No response_