rust-lang / rust-lang/rustfmt

ice: `failed: failed in format_file visitor.buffer`

Open
#6,061 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

!!! REQUIRES DEBUG ASSERTIONS !!!

#[no_mangle]
static FOO: () = ();

fn main() {
    extern "fail
" {
        fn FOO();
    }
    unsafe { FOO() } //~ ERROR: attempt to call an exported symbol that is not defined as a function
}
thread 'main' panicked at /home/matthias/vcs/github/rust_debug_assertions/src/tools/rustfmt/src/formatting.rs:227:9:
assertion `left == right` failed: failed in format_file visitor.buffer:
 "#[no_mangle]\nstatic FOO: () = ();\n\nfn main() {\n    extern \"fail\n\" {\n        fn FOO();\n    }\n    unsafe { FOO() } //~ ERROR: attempt to call an exported symbol that is not defined as a function\n}\n"
  left: 9
 right: 10
stack backtrace:
   0:     0x7fd18dd7ca5d - std::backtrace_rs::backtrace::libunwind::trace::hb28aaf5f3549701f
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7fd18dd7ca5d - std::backtrace_rs::backtrace::trace_unsynchronized::he4f17ec88b61fea5
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fd18dd7ca5d - std::sys_common::backtrace::_print_fmt::h5a82a3e85aa2fae5
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7fd18dd7ca5d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb03764486a25b659
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fd18ddc55cf - core::fmt::rt::Argument::fmt::h67bfbe6caf20ecda
                               at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/fmt/rt.rs:142:9
   5:     0x7fd18ddc55cf - core::fmt::write::h2b3e0bd86bdfc209
                               at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/fmt/mod.rs:1120:17
   6:     0x7fd18dd64285 - std::io::Write::write_fmt::hcf7284dad3d07738
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/io/mod.rs:1854:15
   7:     0x7fd18dd7c824 - std::sys_common::backtrace::_print::h1988031c6b9fcf4a
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fd18dd7c824 - std::sys_common::backtrace::print::h81809c76434159ce
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fd18dd4022c - std::panicking::default_hook::{{closure}}::he3de9259d121bac5
  10:     0x7fd18dd3ff00 - std::panicking::default_hook::hcde334a568bf04a2
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:292:9
  11:     0x7fd1908ffe47 - rustc_driver_impl[8889ac64fe77a2fe]::install_ice_hook::{closure#0}
                               at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_driver_impl/src/lib.rs:1340:17
  12:     0x7fd1908ffe47 - <alloc[3b5cf733b6b27210]::boxed::Box<rustc_driver_impl[8889ac64fe77a2fe]::install_ice_hook::{closure#0}> as core[aa444211b5f41879]::ops::function::Fn<(&dyn for<'a, 'b> core[aa444211b5f41879]::ops::function::Fn<(&'a core[aa444211b5f41879]::panic::panic_info::PanicInfo<'b>,), Output = ()> + core[aa444211b5f41879]::marker::Sync + core[aa444211b5f41879]::marker::Send, &core[aa444211b5f41879]::panic::panic_info::PanicInfo)>>::call
                               at /home/matthias/vcs/github/rust_debug_assertions/library/alloc/src/boxed.rs:2029:9
  13:     0x7fd18dd40ae3 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h65cf345775a09bb6
                               at /home/matthias/vcs/github/rust_debug_assertions/library/alloc/src/boxed.rs:2029:9
  14:     0x7fd18dd40ae3 - std::panicking::rust_panic_with_hook::hb041b1849b056e6a
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:785:13
  15:     0x7fd18dd7cf1a - std::panicking::begin_panic_handler::{{closure}}::hae61001f490e889a
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:659:13
  16:     0x7fd18dd7cd26 - std::sys_common::backtrace::__rust_end_short_backtrace::h07aab78c7d5e7b18
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:171:18
  17:     0x7fd18dd40654 - rust_begin_unwind
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:647:5
  18:     0x7fd18dddf965 - core::panicking::panic_fmt::h7cdaca6ac7987f65
                               at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/panicking.rs:72:14
  19:     0x7fd18dde0019 - core::panicking::assert_failed_inner::heed625da7882381e
                               at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/panicking.rs:337:23
  20:     0x55a6e03f112f - core[aa444211b5f41879]::panicking::assert_failed::<usize, usize>
                               at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/panicking.rs:297:5
  21:     0x55a6e03f2227 - <rustfmt_nightly[fe4bb6d079290361]::formatting::FormatContext<rustfmt_nightly[fe4bb6d079290361]::Session<std[1ba472e493b6ecda]::io::stdio::Stdout>>>::format_file
                               at /home/matthias/vcs/github/rust_debug_assertions/src/tools/rustfmt/src/formatting.rs:227:9
  22:     0x55a6e03f2227 - rustfmt_nightly[fe4bb6d079290361]::formatting::format_project::<rustfmt_nightly[fe4bb6d079290361]::Session<std[1ba472e493b6ecda]::io::stdio::Stdout>>
                               at /home/matthias/vcs/github/rust_debug_assertions/src/tools/rustfmt/src/formatting.rs:162:9
  23:     0x55a6e03e0955 - <rustfmt_nightly[fe4bb6d079290361]::Session<std[1ba472e493b6ecda]::io::stdio::Stdout>>::format_input_inner::{closure#0}
                               at /home/matthias/vcs/github/rust_debug_assertions/src/tools/rustfmt/src/formatting.rs:48:33
  24:     0x55a6e03e0955 - <scoped_tls[af7c8664e9f149d3]::ScopedKey<rustc_span[9066a7c1991c4c44]::SessionGlobals>>::with::<<rustfmt_nightly[fe4bb6d079290361]::Session<std[1ba472e493b6ecda]::io::stdio::Stdout>>::format_input_inner::{closure#0}, core[aa444211b5f41879]::result::Result<rustfmt_nightly[fe4bb6d079290361]::FormatReport, rustfmt_nightly[fe4bb6d079290361]::ErrorKind>>
                               at /home/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/scoped-tls-1.0.1/src/lib.rs:171:13
  25:     0x55a6e03ddf74 - rustc_span[9066a7c1991c4c44]::create_session_if_not_set_then::<core[aa444211b5f41879]::result::Result<rustfmt_nightly[fe4bb6d079290361]::FormatReport, rustfmt_nightly[fe4bb6d079290361]::ErrorKind>, <rustfmt_nightly[fe4bb6d079290361]::Session<std[1ba472e493b6ecda]::io::stdio::Stdout>>::format_input_inner::{closure#0}>::{closure#0}
                               at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_span/src/lib.rs:151:50
  26:     0x55a6e03ddf74 - <scoped_tls[af7c8664e9f149d3]::ScopedKey<rustc_span[9066a7c1991c4c44]::SessionGlobals>>::set::<rustc_span[9066a7c1991c4c44]::create_session_if_not_set_then<core[aa444211b5f41879]::result::Result<rustfmt_nightly[fe4bb6d079290361]::FormatReport, rustfmt_nightly[fe4bb6d079290361]::ErrorKind>, <rustfmt_nightly[fe4bb6d079290361]::Session<std[1ba472e493b6ecda]::io::stdio::Stdout>>::format_input_inner::{closure#0}>::{closure#0}, core[aa444211b5f41879]::result::Result<rustfmt_nightly[fe4bb6d079290361]::FormatReport, rustfmt_nightly[fe4bb6d079290361]::ErrorKind>>
                               at /home/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/scoped-tls-1.0.1/src/lib.rs:137:9
  27:     0x55a6e03ec8af - rustc_span[9066a7c1991c4c44]::create_session_if_not_set_then::<core[aa444211b5f41879]::result::Result<rustfmt_nightly[fe4bb6d079290361]::FormatReport, rustfmt_nightly[fe4bb6d079290361]::ErrorKind>, <rustfmt_nightly[fe4bb6d079290361]::Session<std[1ba472e493b6ecda]::io::stdio::Stdout>>::format_input_inner::{closure#0}>
                               at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_span/src/lib.rs:151:9
  28:     0x55a6e03e14c9 - <rustfmt_nightly[fe4bb6d079290361]::Session<std[1ba472e493b6ecda]::io::stdio::Stdout>>::format_input_inner
                               at /home/matthias/vcs/github/rust_debug_assertions/src/tools/rustfmt/src/formatting.rs:38:9
  29:     0x55a6e03cec97 - <rustfmt_nightly[fe4bb6d079290361]::Session<std[1ba472e493b6ecda]::io::stdio::Stdout>>::format
                               at /home/matthias/vcs/github/rust_debug_assertions/src/tools/rustfmt/src/lib.rs:465:9
  30:     0x55a6e03cec97 - rustfmt[9b0bb1331446777d]::format_and_emit_report::<std[1ba472e493b6ecda]::io::stdio::Stdout>
                               at /home/matthias/vcs/github/rust_debug_assertions/src/tools/rustfmt/src/bin/main.rs:371:19
  31:     0x55a6e03ddb76 - rustfmt[9b0bb1331446777d]::format::{closure#0}
                               at /home/matthias/vcs/github/rust_debug_assertions/src/tools/rustfmt/src/bin/main.rs:343:21
  32:     0x55a6e03ddb76 - <rustfmt_nightly[fe4bb6d079290361]::Session<std[1ba472e493b6ecda]::io::stdio::Stdout>>::override_config::<rustfmt[9b0bb1331446777d]::format::{closure#0}, ()>
                               at /home/matthias/vcs/github/rust_debug_assertions/src/tools/rustfmt/src/lib.rs:473:22
  33:     0x55a6e03cda17 - rustfmt[9b0bb1331446777d]::format
                               at /home/matthias/vcs/github/rust_debug_assertions/src/tools/rustfmt/src/bin/main.rs:342:17
  34:     0x55a6e03cda17 - rustfmt[9b0bb1331446777d]::execute
                               at /home/matthias/vcs/github/rust_debug_assertions/src/tools/rustfmt/src/bin/main.rs:257:14
  35:     0x55a6e03cb01a - rustfmt[9b0bb1331446777d]::main
                               at /home/matthias/vcs/github/rust_debug_assertions/src/tools/rustfmt/src/bin/main.rs:38:27
  36:     0x55a6e03e2dd3 - <fn() as core[aa444211b5f41879]::ops::function::FnOnce<()>>::call_once
                               at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/ops/function.rs:250:5
  37:     0x55a6e03e2dd3 - std[1ba472e493b6ecda]::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:155:18
  38:     0x55a6e03ee189 - std[1ba472e493b6ecda]::rt::lang_start::<()>::{closure#0}
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/rt.rs:166:18
  39:     0x7fd18dd402c7 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h297db2377758e0cf
                               at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/ops/function.rs:284:13
  40:     0x7fd18dd402c7 - std::panicking::try::do_call::hae59afb433bdb921
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:554:40
  41:     0x7fd18dd402c7 - std::panicking::try::h35e373fc7666cc2e
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:518:19
  42:     0x7fd18dd402c7 - std::panic::catch_unwind::h46e79a28bdb63479
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panic.rs:142:14
  43:     0x7fd18dd402c7 - std::rt::lang_start_internal::{{closure}}::hf3e58066b1096274
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/rt.rs:148:48
  44:     0x7fd18dd402c7 - std::panicking::try::do_call::h100385e03aa55f9a
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:554:40
  45:     0x7fd18dd402c7 - std::panicking::try::h89b6326347797a0c
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:518:19
  46:     0x7fd18dd54ddb - std::panic::catch_unwind::h230c430ad70c1500
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panic.rs:142:14
  47:     0x7fd18dd54ddb - std::rt::lang_start_internal::h2a6bfb497173e897
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/rt.rs:148:20
  48:     0x55a6e03cf8bc - main
  49:     0x7fd18dabacd0 - <unknown>
  50:     0x7fd18dabad8a - __libc_start_main
  51:     0x55a6e03b1cd5 - _start
  52:                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 attach the file at `/tmp/im/rustc-ice-2024-02-07T19_30_52-3961474.txt` to your bug report

query stack during panic:
end of query stack

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducer in the issue and the failing assertion in src/tools/rustfmt/src/formatting.rs:227, within FormatContext::format_file. Run rustfmt with debug assertions on this input and inspect the reported visitor.buffer length mismatch. Done means the input no longer triggers the assertion while formatting completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.