Skip to content

Encountered cargo fmt ICE when writing complicated match statements with field names containing greek letters and trailing space after comma #6523

Open
@xiyuzhai

Description

@xiyuzhai

I encountered a similar bug.

See https://github.com/xiyuzhai/cargo-fmt-bug-report0.

Run

cargo fmt

Then the compiler will panic like:

thread 'main' panicked at /rust/deps/annotate-snippets-0.9.2/src/display_list/from_snippet.rs:275:9:
SourceAnnotation range `(22, 23)` is bigger than source length `22`
stack backtrace:
   0:     0x737704adfb8a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hfc616348d9ad0abc
   1:     0x737705214d26 - core::fmt::write::h7ca648217bc79799
   2:     0x737706118711 - std::io::Write::write_fmt::h7960c58bfa5ccbcb
   3:     0x737704adf9e2 - std::sys::backtrace::BacktraceLock::print::h3fb349e80cbe0423
   4:     0x737704ae1f87 - std::panicking::default_hook::{{closure}}::h3366e5842cba645d
   5:     0x737704ae1d70 - std::panicking::default_hook::hd7573a5d4879884b
   6:     0x737703c51c48 - std[26cf95b4f122e720]::panicking::update_hook::<alloc[653926f6abfe8a8a]::boxed::Box<rustc_driver_impl[bcf7efa42268b866]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x737704ae2813 - std::panicking::rust_panic_with_hook::h66e909d048c263a9
   8:     0x737704ae250a - std::panicking::begin_panic_handler::{{closure}}::h8d9aa8be7e8634cf
   9:     0x737704ae0069 - std::sys::backtrace::__rust_end_short_backtrace::h7d7e47ef99abf6aa
  10:     0x737704ae21cd - rust_begin_unwind
  11:     0x7377017a0ef0 - core::panicking::panic_fmt::hf8ffc7c15bfb58a0
  12:     0x5c45a7df2df4 - <annotate_snippets[bc1df9f5ebeb2ffa]::display_list::structs::DisplayList as core[1d264cc251a564c0]::convert::From<annotate_snippets[bc1df9f5ebeb2ffa]::snippet::Snippet>>::from
  13:     0x5c45a7c19f04 - <rustfmt_nightly[e136508bb0dd5df4]::format_report_formatter::FormatReportFormatter as core[1d264cc251a564c0]::fmt::Display>::fmt
  14:     0x737705214d26 - core::fmt::write::h7ca648217bc79799
  15:     0x737704ad3e3e - <&std::io::stdio::Stderr as std::io::Write>::write_fmt::hc6e2c058ec27a44d
  16:     0x737704ad47d8 - std::io::stdio::_eprint::h5c350ea4f4914e82
  17:     0x5c45a7b14353 - rustfmt[f731163ddbbda32b]::format_and_emit_report::<std[26cf95b4f122e720]::io::stdio::Stdout>
  18:     0x5c45a7b11d84 - rustfmt[f731163ddbbda32b]::execute
  19:     0x5c45a7b0e35c - rustfmt[f731163ddbbda32b]::main
  20:     0x5c45a7b02a93 - std[26cf95b4f122e720]::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  21:     0x5c45a7b03019 - std[26cf95b4f122e720]::rt::lang_start::<()>::{closure#0}
  22:     0x737706086208 - std::rt::lang_start_internal::heee0af441e41a6d2
  23:     0x5c45a7b153b8 - main
  24:     0x73770022a1ca - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  25:     0x73770022a28b - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  26:     0x5c45a7af6529 - <unknown>
  27:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rustfmt/issues/new?labels=bug

note: rustc 1.85.1 (4eb161250 2025-03-15) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

The source code in the example isn't exactly very minimal. Because if I reduce the lines, the error will mysteriously go away.

Originally posted by @xiyuzhai in #6392

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPanic, non-idempotency, invalid code, etc.fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions