Skip to content

bug: panics on slice index error when formatting malformed doc comment #6762

@moyanj

Description

@moyanj

rustc version: 1.94.0-nightly (31cd367b9 2026-01-08)
platform: x86_64-unknown-linux-gnu

When rustfmt is invoked by rust-analyzer in VSCode for automatic formatting, it panics with a slice index error when encountering malformed documentation comments.

Reproduction Code

struct A {
    pub nlinks: u64/// ssss
}

Observe the panic in rust-analyzer logs and rust-ice-xxxx.txt in file dir.

Backtarce

thread 'main' panicked at /rustc-dev/31cd367b9ca1ce359268e7adf4ea540408c0ad85/library/alloc/src/vec/mod.rs:2865:36:
slice index starts at 24 but ends at 20
stack backtrace:
   0:     0x720673a12bdb - <std[5e3fd61f923da6c8]::backtrace::Backtrace>::create
   1:     0x720673a12b25 - <std[5e3fd61f923da6c8]::backtrace::Backtrace>::force_capture
   2:     0x720672a05a47 - std[5e3fd61f923da6c8]::panicking::update_hook::<alloc[4cad7486372ceb04]::boxed::Box<rustc_driver_impl[f8637fc8d48c8951]::install_ice_hook::{closure#1}>>::{closure#0}
   3:     0x720673a25ff2 - std[5e3fd61f923da6c8]::panicking::panic_with_hook
   4:     0x720673a08138 - std[5e3fd61f923da6c8]::panicking::panic_handler::{closure#0}
   5:     0x7206739fedf9 - std[5e3fd61f923da6c8]::sys::backtrace::__rust_end_short_backtrace::<std[5e3fd61f923da6c8]::panicking::panic_handler::{closure#0}, !>
   6:     0x720673a09c0d - __rustc[f3d9969b214b7ee8]::rust_begin_unwind
   7:     0x7206706063bc - core[63159e14536656d8]::panicking::panic_fmt
   8:     0x7206701b50fd - core[63159e14536656d8]::slice::index::slice_index_fail
   9:     0x720672a592db - <rustc_errors[52ac9412f380f3dc]::styled_buffer::StyledBuffer>::replace
  10:     0x720672a49196 - <rustc_errors[52ac9412f380f3dc]::emitter::HumanEmitter>::emit_messages_default_inner::{closure#0}
  11:     0x720672a609cf - <rustc_errors[52ac9412f380f3dc]::emitter::HumanEmitter as rustc_errors[52ac9412f380f3dc]::emitter::Emitter>::emit_diagnostic
  12:     0x5f5c36ca7e2c - <rustfmt_nightly[71d5c4d38154ed5a]::parse::session::SilentOnIgnoredFilesEmitter as rustc_errors[52ac9412f380f3dc]::emitter::Emitter>::emit_diagnostic
  13:     0x72067553497d - <rustc_errors[52ac9412f380f3dc]::DiagCtxtInner>::emit_diagnostic::{closure#3}
  14:     0x720672a2beff - rustc_errors[52ac9412f380f3dc]::default_track_diagnostic::<core[63159e14536656d8]::option::Option<rustc_span[645e6eaf91144e9d]::ErrorGuaranteed>>
  15:     0x720675531474 - <rustc_errors[52ac9412f380f3dc]::DiagCtxtInner>::emit_diagnostic
  16:     0x720675531331 - <rustc_errors[52ac9412f380f3dc]::DiagCtxtHandle>::emit_diagnostic
  17:     0x720670c7294c - <rustc_span[645e6eaf91144e9d]::ErrorGuaranteed as rustc_errors[52ac9412f380f3dc]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x720674798d47 - <rustc_parse[7385968f4ed495e8]::parser::Parser>::parse_field_def::{closure#0}
  19:     0x720674d58885 - <rustc_parse[7385968f4ed495e8]::parser::Parser>::parse_record_struct_body
  20:     0x720674d57f82 - <rustc_parse[7385968f4ed495e8]::parser::Parser>::parse_item_struct
  21:     0x720674d7bd91 - <rustc_parse[7385968f4ed495e8]::parser::Parser>::parse_item_kind
  22:     0x720674d6547b - <rustc_parse[7385968f4ed495e8]::parser::Parser>::parse_item_common
  23:     0x720674d64511 - <rustc_parse[7385968f4ed495e8]::parser::Parser>::parse_item_
  24:     0x720674d63bda - <rustc_parse[7385968f4ed495e8]::parser::Parser>::parse_mod
  25:     0x7206717ff7b3 - <rustc_parse[7385968f4ed495e8]::parser::Parser>::parse_crate_mod
  26:     0x5f5c36c1eda8 - <rustfmt_nightly[71d5c4d38154ed5a]::parse::parser::Parser>::parse_crate
  27:     0x5f5c36b5535f - <rustfmt_nightly[71d5c4d38154ed5a]::Session<std[5e3fd61f923da6c8]::io::stdio::Stdout>>::format_input_inner::{closure#0}
  28:     0x5f5c36b47397 - rustfmt[22ca6d87ec2711c5]::format_and_emit_report::<std[5e3fd61f923da6c8]::io::stdio::Stdout>
  29:     0x5f5c36b5bf6c - rustfmt[22ca6d87ec2711c5]::execute
  30:     0x5f5c36b57cf7 - rustfmt[22ca6d87ec2711c5]::main
  31:     0x5f5c36b529f3 - std[5e3fd61f923da6c8]::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  32:     0x5f5c36b530d9 - std[5e3fd61f923da6c8]::rt::lang_start::<()>::{closure#0}
  33:     0x72067510e9e6 - std[5e3fd61f923da6c8]::rt::lang_start_internal
  34:     0x5f5c36b67638 - main
  35:     0x72066ea27635 - <unknown>
  36:     0x72066ea276e9 - __libc_start_main
  37:     0x5f5c36a4c779 - <unknown>
  38:                0x0 - <unknown>


rustc version: 1.94.0-nightly (31cd367b9 2026-01-08)
platform: x86_64-unknown-linux-gnu

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-needs-reproStatus: this issue has no reproduction and needs a reproduction to make progress

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions