Skip to content

[bug] wrap_comments #6586

Open
Open
@yuanair

Description

@yuanair

Just add this line to your rust source file and enable wrap_comment and BOOM!

// > >

Version

air@air-ubuntu:/tmp/test$ rustup update
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: checking for self-update

  nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.90.0-nightly (706f244db 2025-06-23)

info: cleaning up downloads & tmp directories
air@air-ubuntu:/tmp/test$ rustfmt --version
rustfmt 1.8.0-nightly (706f244db5 2025-06-23)

Output

air@air-ubuntu:/tmp/test$ rustfmt main.rs --config=wrap_comments=true

thread 'main' panicked at src/tools/rustfmt/src/comment.rs:503:29:
byte index 4 is out of bounds of `> >`
stack backtrace:
   0:     0x791bc96cd4f3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h9bc630a44ef1bd37
   1:     0x791bc9e02c3f - core::fmt::write::h8d4882cfa37be9ef
   2:     0x791bc96c3123 - std::io::Write::write_fmt::hb6d712098c1ec657
   3:     0x791bc96cd352 - std::sys::backtrace::BacktraceLock::print::hfdda47e85b5c376e
   4:     0x791bc96d0e4a - std::panicking::default_hook::{{closure}}::h7e0891018eef2db1
   5:     0x791bc96d09cf - std::panicking::default_hook::h2a527dcc7b760697
   6:     0x791bc87c6563 - std[d72cce7acc933e06]::panicking::update_hook::<alloc[f1b445a52707e7c1]::boxed::Box<rustc_driver_impl[d09187272c6ff4c]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x791bc96d169b - std::panicking::rust_panic_with_hook::h6895b0dbd1680e6c
   8:     0x791bc96d139a - std::panicking::begin_panic_handler::{{closure}}::h4db58249c0dbe742
   9:     0x791bc96cd9c9 - std::sys::backtrace::__rust_end_short_backtrace::hedbaf3e8e3747461
  10:     0x791bc96d107d - __rustc[4ee5ea153edad2d5]::rust_begin_unwind
  11:     0x791bc5e8fcf0 - core::panicking::panic_fmt::h275f728813c34539
  12:     0x791bc81c395f - core::str::slice_error_fail_rt::h4045214c5b88d382
  13:     0x791bc7c4754a - core::str::slice_error_fail::heb221fd77d12a794
  14:     0x5a2fb6703e61 - rustfmt_nightly[39a92fabb7bc0beb]::comment::rewrite_comment_inner
  15:     0x5a2fb66fe439 - rustfmt_nightly[39a92fabb7bc0beb]::comment::identify_comment
  16:     0x5a2fb6768da5 - <rustfmt_nightly[39a92fabb7bc0beb]::visitor::FmtVisitor>::process_comment
  17:     0x5a2fb6767d26 - <rustfmt_nightly[39a92fabb7bc0beb]::visitor::FmtVisitor>::format_missing_inner::<<rustfmt_nightly[39a92fabb7bc0beb]::visitor::FmtVisitor>::format_missing_indent::{closure#0}>
  18:     0x5a2fb67affa5 - <rustfmt_nightly[39a92fabb7bc0beb]::visitor::FmtVisitor>::format_separate_mod
  19:     0x5a2fb666fb1c - <rustfmt_nightly[39a92fabb7bc0beb]::Session<std[d72cce7acc933e06]::io::stdio::Stdout>>::format_input_inner::{closure#0}
  20:     0x5a2fb66813d4 - rustfmt[e943311df3bc7469]::format_and_emit_report::<std[d72cce7acc933e06]::io::stdio::Stdout>
  21:     0x5a2fb667f409 - rustfmt[e943311df3bc7469]::execute
  22:     0x5a2fb667acab - rustfmt[e943311df3bc7469]::main
  23:     0x5a2fb666c4c3 - std[d72cce7acc933e06]::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  24:     0x5a2fb666ca79 - std[d72cce7acc933e06]::rt::lang_start::<()>::{closure#0}
  25:     0x791bcb03bdb2 - std::rt::lang_start_internal::h3318bf0b696e540b
  26:     0x5a2fb66826d8 - main
  27:     0x791bc482a1ca - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  28:     0x791bc482a28b - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  29:     0x5a2fb6545a59 - <unknown>
  30:                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: please make sure that you have updated to the latest nightly

note: please attach the file at `/tmp/test/rustc-ice-2025-06-24T08_44_52-395430.txt` to your bug report

query stack during panic:
end of query stack
air@air-ubuntu:/tmp/test$ 

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-commentsbugPanic, non-idempotency, invalid code, etc.only-with-optionrequires a non-default option value to reproduce

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions