Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing --error-format=json does not impact panic message format #107484

Open
celinval opened this issue Jan 30, 2023 · 0 comments
Open

Passing --error-format=json does not impact panic message format #107484

celinval opened this issue Jan 30, 2023 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@celinval
Copy link
Contributor

Code

//! 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

{"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

{"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

@celinval celinval added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 30, 2023
@jyn514 jyn514 added the D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. label Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants