Skip to content

rustfmt failed with use underscore prefixed name #6668

@wizardxz

Description

@wizardxz
~/tmp/repro master* ❯ cat src/main.rs
use sql::{
    _bind_this_one_has_underscore, A1, A2, A3, A4, A5, A6, A7, A9, UnescapeOptions, bind_11,
    bind_12, build_13, check_14, check_15, coerce_16, construct_17, construct_18, create_19, df_20,
    expand_21,
};

~/tmp/repro master* ❯ rustfmt src/main.rs                                                                                                                                                                                                                                                                                                                                                                                                                                             
thread 'main' panicked at library/core/src/slice/sort/shared/smallsort.rs:860:5:
user-provided comparison function does not correctly implement a total order
stack backtrace:
   0:     0x732ab9200f83 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hdcfcb6d4c8489523
   1:     0x732ab9a02d77 - core::fmt::write::h8a494366950f23bb
   2:     0x732abadd14d1 - std::io::Write::write_fmt::h6556609fca33d0b1
   3:     0x732ab9200de2 - std::sys::backtrace::BacktraceLock::print::hb2a626a81e06b2dc
   4:     0x732ab9204887 - std::panicking::default_hook::{{closure}}::h4f78485264f12d10
   5:     0x732ab92043eb - std::panicking::default_hook::h2c66fc99e962531d
   6:     0x732ab82627e3 - std[9479b33d5e275715]::panicking::update_hook::<alloc[252dd2b3abdfe4a]::boxed::Box<rustc_driver_impl[773a1ede480c2143]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x732ab92050ce - std::panicking::rust_panic_with_hook::h33ac55f64bbd807d
   8:     0x732ab9204d96 - std::panicking::begin_panic_handler::{{closure}}::h30e7cb89678a57fe
   9:     0x732ab9201459 - std::sys::backtrace::__rust_end_short_backtrace::hed60f27456c16ced
  10:     0x732ab9204aad - __rustc[de2ca18b4c54d5b8]::rust_begin_unwind
  11:     0x732ab58d01a0 - core::panicking::panic_fmt::h62f63d096dd276af
  12:     0x732ab7c1cddb - core::slice::sort::shared::smallsort::panic_on_ord_violation::h5994bbfe0e95ef55
  13:     0x57415d2caa60 - core[42326c15e70145c1]::slice::sort::stable::quicksort::quicksort::<rustfmt_nightly[8838cd23bc40e56a]::imports::UseTree, <rustfmt_nightly[8838cd23bc40e56a]::imports::UseTree as core[42326c15e70145c1]::cmp::PartialOrd>::lt>
  14:     0x57415d2c7fe7 - core[42326c15e70145c1]::slice::sort::stable::drift::sort::<rustfmt_nightly[8838cd23bc40e56a]::imports::UseTree, <rustfmt_nightly[8838cd23bc40e56a]::imports::UseTree as core[42326c15e70145c1]::cmp::PartialOrd>::lt>
  15:     0x57415d2c6e06 - core[42326c15e70145c1]::slice::sort::stable::driftsort_main::<rustfmt_nightly[8838cd23bc40e56a]::imports::UseTree, <rustfmt_nightly[8838cd23bc40e56a]::imports::UseTree as core[42326c15e70145c1]::cmp::PartialOrd>::lt, alloc[252dd2b3abdfe4a]::vec::Vec<rustfmt_nightly[8838cd23bc40e56a]::imports::UseTree>>
  16:     0x57415d3596ec - <rustfmt_nightly[8838cd23bc40e56a]::imports::UseTree>::normalize
  17:     0x57415d2f8385 - <core[42326c15e70145c1]::iter::adapters::filter_map::FilterMap<core[42326c15e70145c1]::slice::iter::Iter<&rustc_ast[cdaf044baa5222af]::ast::Item>, rustfmt_nightly[8838cd23bc40e56a]::reorder::rewrite_reorderable_or_regroupable_items::{closure#0}> as core[42326c15e70145c1]::iter::traits::iterator::Iterator>::next
  18:     0x57415d3ace24 - <rustfmt_nightly[8838cd23bc40e56a]::visitor::FmtVisitor>::visit_items_with_reordering
  19:     0x57415d3d2d67 - <rustfmt_nightly[8838cd23bc40e56a]::visitor::FmtVisitor>::format_separate_mod
  20:     0x57415d29a2e2 - <rustfmt_nightly[8838cd23bc40e56a]::Session<std[9479b33d5e275715]::io::stdio::Stdout>>::format_input_inner::{closure#0}
  21:     0x57415d2ab014 - rustfmt[1bccd44b51d69c4e]::format_and_emit_report::<std[9479b33d5e275715]::io::stdio::Stdout>
  22:     0x57415d2a98df - rustfmt[1bccd44b51d69c4e]::execute
  23:     0x57415d2a51d5 - rustfmt[1bccd44b51d69c4e]::main
  24:     0x57415d296cd3 - std[9479b33d5e275715]::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  25:     0x57415d297289 - std[9479b33d5e275715]::rt::lang_start::<()>::{closure#0}
  26:     0x732abab7c451 - std::rt::lang_start_internal::h34f9328d113fd60a
  27:     0x57415d2ac318 - main
  28:     0x732ab422a1ca - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  29:     0x732ab422a28b - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  30:     0x57415d171079 - <unknown>
  31:                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.90.0 (1159e78c4 2025-09-14) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

But if the underscore prefix does not exist, it is good

~/tmp/repro master* ❯ cat src/main.rs
use sql::{
    bind_this_one_has_underscore, A1, A2, A3, A4, A5, A6, A7, A9, UnescapeOptions, bind_11,
    bind_12, build_13, check_14, check_15, coerce_16, construct_17, construct_18, create_19, df_20,
    expand_21,
};
~/tmp/repro master* ❯ rustfmt src/main.rs
~/tmp/repro master* ❯ echo $?
0
~/tmp/repro master* ❯     

The rustfmt +nightly src/main.rs also re-produce the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions