Skip to content

rustc explain panics with error code longer than 4 digits #140647

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

Closed
chputnam opened this issue May 4, 2025 · 1 comment · Fixed by #140700
Closed

rustc explain panics with error code longer than 4 digits #140647

chputnam opened this issue May 4, 2025 · 1 comment · Fixed by #140700
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@chputnam
Copy link

chputnam commented May 4, 2025

The following command line causes rustc to panic:

rustc --explain E10000

Based on the panic message, any error code above 9999 likely triggers this panic.
rustc --version --verbose:

rustc 1.88.0-nightly (d6a325d93 2025-05-03)
binary: rustc
commit-hash: d6a325d93a84077580c677f89affbe45682606c3
commit-date: 2025-05-03
host: x86_64-pc-windows-msvc
release: 1.88.0-nightly
LLVM version: 20.1.4

It appears that the panicking assertion assumes that code further up the stack does basic validation of the error code, when in fact that isn't happening.

Error output

thread 'main' panicked at /rustc/d6a325d93a84077580c677f89affbe45682606c3\compiler\rustc_errors\src\codes.rs:9:1:
assertion failed: value <= 9999
stack backtrace:
   0:     0x7ff992ebd4c2 - std::backtrace_rs::backtrace::win64::trace
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\..\..\backtrace\src\backtrace\win64.rs:85
   1:     0x7ff992ebd4c2 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ff992ebd4c2 - std::sys::backtrace::_print_fmt
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\sys\backtrace.rs:66
   3:     0x7ff992ebd4c2 - std::sys::backtrace::impl$0::print::impl$0::fmt
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\sys\backtrace.rs:39
   4:     0x7ff992eefccb - core::fmt::rt::Argument::fmt
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\core\src\fmt\rt.rs:181
   5:     0x7ff992eefccb - core::fmt::write
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\core\src\fmt\mod.rs:1446
   6:     0x7ff992eb3577 - std::io::default_write_fmt
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\io\mod.rs:639
   7:     0x7ff992eb3577 - std::io::Write::write_fmt<std::sys::stdio::windows::Stderr>
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\io\mod.rs:1914
   8:     0x7ff992ebd305 - std::sys::backtrace::BacktraceLock::print
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\sys\backtrace.rs:42
   9:     0x7ff992ec2faa - std::panicking::default_hook::closure$0
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\panicking.rs:300
  10:     0x7ff992ec2d40 - std::panicking::default_hook
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\panicking.rs:327
  11:     0x7ff9945c40c9 - core[87a27484b78f7475]::slice::sort::unstable::heapsort::heapsort::<((rustc_lint_defs[b0c94f99b9e7b658]::Level, &str), usize), <((rustc_lint_defs[b0c94f99b9e7b658]::Level, &str), usize) as core[87a27484b78f7475]::cmp::PartialOrd>::lt>
  12:     0x7ff992ec3c3e - std::panicking::rust_panic_with_hook
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\panicking.rs:841
  13:     0x7ff992ec3962 - std::panicking::begin_panic_handler::closure$0
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\panicking.rs:699
  14:     0x7ff992ebe28f - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\sys\backtrace.rs:168
  15:     0x7ff992ec359e - std::panicking::begin_panic_handler
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\panicking.rs:697
  16:     0x7ff996030751 - core::panicking::panic_fmt
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\core\src\panicking.rs:75
  17:     0x7ff99603080d - core::panicking::panic
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\core\src\panicking.rs:145
  18:     0x7ff98f7f8387 - rustc_driver_impl[4bf9a847fe62d732]::run_compiler
  19:     0x7ff98f8039c7 - rustc_driver_impl[4bf9a847fe62d732]::main
  20:     0x7ff7bb711039 - _wctype
  21:     0x7ff7bb711006 - _wctype
  22:     0x7ff7bb71101c - _wctype
  23:     0x7ff992ea280c - std::rt::lang_start_internal::closure$0
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\rt.rs:168
  24:     0x7ff992ea280c - std::panicking::try::do_call
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\panicking.rs:589
  25:     0x7ff992ea280c - std::panicking::try
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\panicking.rs:552
  26:     0x7ff992ea280c - std::panic::catch_unwind
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\panic.rs:359
  27:     0x7ff992ea280c - std::rt::lang_start_internal
                               at /rustc/d6a325d93a84077580c677f89affbe45682606c3/library\std\src\rt.rs:164
  28:     0x7ff7bb71106a - main
  29:     0x7ff7bb71126c - invoke_main
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  30:     0x7ff7bb71126c - __scrt_common_main_seh
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  31:     0x7ffa7b61e8d7 - BaseThreadInitThunk
  32:     0x7ffa7c8114fc - RtlUserThreadStart

error: the compiler unexpectedly panicked. this is a bug.
@chputnam chputnam added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 4, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 4, 2025
@jieyouxu jieyouxu added A-diagnostics Area: Messages for errors, warnings, and lints P-low Low priority and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 5, 2025
@Kivooeo
Copy link
Contributor

Kivooeo commented May 6, 2025

@rustbot claim

@bors bors closed this as completed in 7d372ae May 8, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 8, 2025
Rollup merge of rust-lang#140700 - Kivooeo:new-fix-six, r=davidtwco,fmease

Don't crash on error codes passed to `--explain` which exceed our internal limit of 9999

removed panic in case where we do `--explain > 9999` and added check for it

now error looks like this instead of ICE
```
$ rustc.exe --explain E10000
error: E10000 is not a valid error code
```
fixes rust-lang#140647
r? `@fmease`
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 C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants