Skip to content

[ICE]: rustc --explain E0602 with syntax highlighting #156326

@m4rch3n1ng

Description

@m4rch3n1ng

Code

use the following command (either in an interactive tty or with the --color always flag specified):

rustc --explain E0602

Meta

still fails on the latest nightly (rustc 1.96.0-beta.5 (a5a9a5438 2026-05-01)).

bisected using cargo-bisect-rustc:

searched nightlies: from nightly-2026-01-17 to nightly-2026-05-08
regressed nightly: nightly-2026-01-21
searched commit range: d940e56...5c49c4f
regressed commit: 63f4513

regressed in 28b763d, cc #150895

how to reproduce using cargo-bisect-rustc

make a libisatty.c file to trick rustc into believing it is in an interactive tty (using --color always doesn't work, as it would then point to 9b07264):

/**
 * Overrides the glibc function. Will always return true.
 *
 * Note: Although this should be okay for most applications it
 * can lead to unwanted side effects. It depends on why the
 * program calls isatty().
 */
int isatty(int param) {
    return 1;
}

run the following command:

$ gcc -shared -o libisatty.so libisatty.c

make a explain.sh file with the following:

#!/bin/bash

export LD_PRELOAD=./libisatty.so
rustc --explain E0602

and then run cargo bisect-rustc:

$ cargo bisect-rustc --start=1.94.0 --script explain.sh

Error output

thread 'main' (1152836) panicked at /rustc-dev/a5a9a5438ba8f6b83523031de99b15c12b44cea4/compiler/rustc_driver_impl/src/highlighter.rs:109:28:
end byte index 28 is out of bounds for string of length 27
Backtrace

thread 'main' (1147454) panicked at /rustc-dev/59807616e1fa2540724bfbac14d7976d7e4a3860/compiler/rustc_driver_impl/src/highlighter.rs:109:28:
end byte index 28 is out of bounds of `rustc -D bogus rust_file.rs`
stack backtrace:
   0:     0x7f304679314b - <<std[e28293b1aa0f68bd]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[c1f1a4ba060b9bfa]::fmt::Display>::fmt
   1:     0x7f3046e1f408 - core[c1f1a4ba060b9bfa]::fmt::write
   2:     0x7f30483683b6 - <std[e28293b1aa0f68bd]::sys::stdio::unix::Stderr as std[e28293b1aa0f68bd]::io::Write>::write_fmt
   3:     0x7f3046769238 - std[e28293b1aa0f68bd]::panicking::default_hook::{closure#0}
   4:     0x7f30467865b3 - std[e28293b1aa0f68bd]::panicking::default_hook
   5:     0x7f304575cc30 - std[e28293b1aa0f68bd]::panicking::update_hook::<alloc[fdfd2bd8633a6659]::boxed::Box<rustc_driver_impl[e4ca9dd5dd6cf2a8]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f3046786892 - std[e28293b1aa0f68bd]::panicking::panic_with_hook
   7:     0x7f30467692f8 - std[e28293b1aa0f68bd]::panicking::panic_handler::{closure#0}
   8:     0x7f3046760029 - std[e28293b1aa0f68bd]::sys::backtrace::__rust_end_short_backtrace::<std[e28293b1aa0f68bd]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f304676ad5d - __rustc[b7974e8690430dd9]::rust_begin_unwind
  10:     0x7f30434de82c - core[c1f1a4ba060b9bfa]::panicking::panic_fmt
  11:     0x7f30450a8bb1 - core[c1f1a4ba060b9bfa]::str::slice_error_fail_rt
  12:     0x7f30433558da - core[c1f1a4ba060b9bfa]::str::slice_error_fail
  13:     0x7f3045761033 - <rustc_driver_impl[e4ca9dd5dd6cf2a8]::highlighter::Highlighter>::highlight_rustc_lexer
  14:     0x7f304575f9e9 - <rustc_driver_impl[e4ca9dd5dd6cf2a8]::highlighter::highlight as core[c1f1a4ba060b9bfa]::ops::function::FnOnce<(&str, &mut alloc[fdfd2bd8633a6659]::vec::Vec<u8>)>>::call_once::{shim:vtable#0}
  15:     0x7f3045792d4b - rustc_errors[795cd5cf46ddce51]::markdown::term::write_stream
  16:     0x7f3044b12dff - <rustc_errors[795cd5cf46ddce51]::markdown::MdStream>::write_anstream_buf
  17:     0x7f3047e6b1d5 - rustc_driver_impl[e4ca9dd5dd6cf2a8]::run_compiler
  18:     0x7f3047e635c3 - rustc_driver_impl[e4ca9dd5dd6cf2a8]::main
  19:     0x55a82d455043 - std[e28293b1aa0f68bd]::sys::backtrace::__rust_begin_short_backtrace::<fn() -> std[e28293b1aa0f68bd]::process::ExitCode, std[e28293b1aa0f68bd]::process::ExitCode>
  20:     0x55a82d455039 - <std[e28293b1aa0f68bd]::rt::lang_start<std[e28293b1aa0f68bd]::process::ExitCode>::{closure#0} as core[c1f1a4ba060b9bfa]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  21:     0x7f304802b588 - std[e28293b1aa0f68bd]::rt::lang_start_internal
  22:     0x55a82d493f57 - main
  23:     0x7f30418276c1 - <unknown>
  24:     0x7f30418277f9 - __libc_start_main
  25:     0x55a82d493e66 - <unknown>
  26:                0x0 - <unknown>

error: 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.95.0 (59807616e 2026-04-14) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions