Repository navigation
Description
Code
pub fn f() { let mut foo_bar = 0; }Meta
rustc --version --verbose:
rustc 1.94.0 (4a4ef493e 2026-03-02)
binary: rustc
commit-hash: 4a4ef493e3a1488c6e321570238084b38948f6db
commit-date: 2026-03-02
host: x86_64-unknown-linux-gnu
release: 1.94.0
LLVM version: 21.1.8
Error output
$ rustc --edition=2021 --crate-type lib --diagnostic-width=0 ice.rs
thread 'rustc' panicked at library/alloc/src/vec/mod.rs:2873:36:
slice index starts at 13 but ends at 11
...
12: <annotate_snippets::renderer::styled_buffer::StyledBuffer>::replace
13: annotate_snippets::renderer::render::render
14: <rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter>::emit_messages_default
...
21: rustc_middle::lint::lint_level::lint_level_impl
22: rustc_borrowck::borrowck_check_region_constraints
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new
note: rustc 1.94.0 (4a4ef493e 2026-03-02) running on x86_64-unknown-linux-gnu
Full backtrace
0: <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt
1: core::fmt::write
2: std::io::Write::write_fmt
3: std::panicking::default_hook::{closure}
4: std::panicking::default_hook
5: std::panicking::update_hook::<Box<rustc_driver_impl::install_ice_hook::{closure#1}>>::{closure#0}
6: std::panicking::panic_with_hook
7: std::panicking::panic_handler::{closure}
8: std::sys::backtrace::__rust_end_short_backtrace
9: __rustc::rust_begin_unwind
10: core::panicking::panic_fmt
11: core::slice::index::slice_index_fail
12: <annotate_snippets::renderer::styled_buffer::StyledBuffer>::replace
13: annotate_snippets::renderer::render::render
14: <rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter>::emit_messages_default
15: <AnnotateSnippetEmitter as rustc_errors::emitter::Emitter>::emit_diagnostic
16: <rustc_errors::DiagCtxtInner>::emit_diagnostic::{closure#3}
17: rustc_interface::callbacks::track_diagnostic::<Option<ErrorGuaranteed>>
18: <rustc_errors::DiagCtxtInner>::emit_diagnostic
19: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
20: <() as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
21: rustc_middle::lint::lint_level::lint_level_impl
22: rustc_borrowck::borrowck_check_region_constraints
23: <rustc_borrowck::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
Trigger conditions
- Any
unused_mutwarning where the variable name is 7+ characters (the lint's underline spans 12+ display columns) --diagnostic-widthis 10 or less (including 0, the auto-detected value when there is no TTY)
This is hit in practice by non-interactive environments: CI without a PTY, wsl -e invocations, piped output through tools that don't allocate a terminal, etc.
The crash also produces a secondary delayed_bug about OpaqueTypeKey / ProvisionalHiddenType, but this is collateral damage from the panic aborting the borrow checker -- not an independent type system bug.
Regression
Regression in 1.94.0 (works on 1.93.0). Nightly bisect (regressed nightly-2025-11-23) points to #148984 which upgraded annotate-snippets from 0.11.5 to 0.12.9. The vulnerable StyledBuffer::replace method was introduced in the 0.12.x series.
Update: Regression is 1.91.0 -> 1.92.0, not 1.93.0 -> 1.94.0. See this comment for details.
searched nightlies: nightly-2025-11-01 to nightly-2026-01-20
regressed nightly: nightly-2025-11-23
Root cause
The bug is in annotate-snippets 0.12.10-0.12.13 (still present on main), not in rustc itself. The span-trimming logic in annotate_snippets::renderer::render computes an inverted range when term_width is 0, and StyledBuffer::replace panics on it.
Filed upstream: rust-lang/annotate-snippets-rs#391
Workarounds
RUSTFLAGS="--diagnostic-width=80" cargo build # explicit width
RUSTFLAGS="-A unused-mut" cargo build # suppress the lint
rustup override set 1.93.0 # pin toolchainReproducer repo
https://github.com/furkanmamuk/rustc-ice-diagnostic-width-panic
Activity
furkanmamuk commentedon Mar 23, 2026
Fix PR upstream: rust-lang/annotate-snippets-rs#392
jieyouxu commentedon Mar 23, 2026
@furkanmamuk how do you reproduce the ICE with cargo? I can reproduce it with
rustcbare, but not in conjunction withcargo(absent tiny terminal width).jieyouxu commentedon Mar 23, 2026
Can you also elaborate on your bisection (how did you do this?) The linked PR landed on 1.93.0 not 1.94.0?
furkanmamuk commentedon Mar 23, 2026
@jieyouxu
There's no way to trigger it without a small terminal width,
diagnostic-width <= 10is a hard requirement for the bug. It only shows up in environments where width auto-detects to 0 (WSL2 non-interactive, CI without PTY, piped output with no TTY).To reproduce with cargo:
CARGO_TERM_WIDTH=0 cargo checkorRUSTFLAGS="--diagnostic-width=0" cargo checkThe original discovery was on WSL2 invoked non-interactively (
wsl -e bash -c ...), where/dev/ttyreports size 1x1 -- cargo auto-detects width as 0 and passes--diagnostic-width=0to rustc.My original bisection attribution was wrong. What actually happened:
annotate-snippets0.12.10 inrustc_errors, but uses the old emitter by default -- the vulnerableStyledBuffer::replacecodepath is never hit.(regressed nightly-2025-11-23) actually found.
The bug has been latent in
annotate-snippets0.12.x since it was introduced, but only became reachable in rustc when the emitter switch landed.jieyouxu commentedon Mar 23, 2026
I must ask: was this report AI-generated/LLM-generated?
furkanmamuk commentedon Mar 23, 2026
@jieyouxu No, investigation is mine. I used an ai assistant (claude) to help structure and format the final report, but every test and finding came from actual debugging sessions. I built it while debugging a compiler error that was blocking my POSIX terminal, which I hit with wsl invocations while testing first.
jieyouxu commentedon Mar 23, 2026
searched nightlies: from nightly-2025-09-13 to nightly-2026-03-23
regressed nightly: nightly-2025-10-13
searched commit range: be0ade2...2300c2a
regressed commit: ff6dc92
bisected with cargo-bisect-rustc v0.6.11
Host triple: x86_64-unknown-linux-gnu
Reproduce with:
furkanmamuk commentedon Mar 23, 2026
Correction on regression range, and more findings - This goes deeper than originally reported
Updated version bisect:
--diagnostic-width=0?rustc_errors::styled_buffer::StyledBuffer::replaceviaHumanEmitterrustc_errors::styled_buffer::StyledBuffer::replaceviaHumanEmitterannotate_snippets::renderer::styled_buffer::StyledBuffer::replaceviaAnnotateSnippetEmitterCI matrix confirming the version bisect and width threshold
Nightly bisect (1.91 -> 1.92):
searched nightlies: from nightly-2025-08-01 to nightly-2025-10-30
regressed nightly: nightly-2025-10-13
regressed commit: ff6dc928
The regressing commit is the auto-merge of #142390("Perform unused assignment and unused variables lints on MIR", merged Oct 12, 2025).
This changed how
unused_mutannotations are structured, causing them to hit the pre-existing bug inStyledBuffer::replaceat small terminal widths.StyledBuffer::replacehas never guarded against inverted ranges. Before #142390, the annotation geometry didn't trigger the bad path at width=0. After #142390, it does.In 1.94.0, the default emitter switched to annotate-snippets (#150032), which has its own copy of the same bug, so the crash moved from
rustc_errors::StyledBuffertoannotate_snippets::StyledBuffer.Fix status:
rustc_errors::styled_buffer(1.92.0-1.93.0): removed from rustc main when the emitter switched. A backport to stable would need to patch the oldStyledBuffer::replace.grindvoll commentedon Mar 24, 2026
I hit the same (or at least related) problem today with 1.94 - I noticed a crash in the output from the rust-analyzer plugin in VsCode.
rust-analyzerplugin uses--diagnostic-width=0, and after narrowing down, it ends up with the same conclusion as described here - a bug inStyledBuffer::replace.This is another code snippet that reveals the panic:
In this case, the unknown import error is the trigger. The length of the import (
aaaaaaaaaaa) must be 11 or 12 for the panic to happen.Regression info:
The example in this comment generates a panic in all rust versions >= 1.87.
Auto merge of #154914 - Muscraft:update-annotate-snippets, r=jieyouxu
Auto merge of #154914 - Muscraft:update-annotate-snippets, r=jieyouxu
Auto merge of #154914 - Muscraft:update-annotate-snippets, r=jieyouxu
Auto merge of #154914 - Muscraft:update-annotate-snippets, r=jieyouxu
rustcpanics with some values ofdiagnostic-width#156180 as a duplicate of this issue