Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ice: failed: failed in format_file visitor.buffer #6061

Open
matthiaskrgr opened this issue Feb 7, 2024 · 3 comments
Open

ice: failed: failed in format_file visitor.buffer #6061

matthiaskrgr opened this issue Feb 7, 2024 · 3 comments
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@matthiaskrgr
Copy link
Member

!!! 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
@ytmimi
Copy link
Contributor

ytmimi commented Feb 7, 2024

!!! REQUIRES DEBUG ASSERTIONS !!!

@matthiaskrgr what version of rustfmt were you using and how can this be reproduced?

@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Feb 7, 2024

I bootstrap my own rustc toolchain (from git repo) with debug assertions and use the resulting rustfmt binary 😅

commit of the rustc tree was d6c46a23ce19e910225abacc33bcca9d0f549148

@ytmimi
Copy link
Contributor

ytmimi commented Feb 7, 2024

Thanks for the info! I haven't had a chance to see why this is failing, but for now here's the location of where the issue is:

rustfmt/src/formatting.rs

Lines 227 to 232 in ead0fc9

debug_assert_eq!(
visitor.line_number,
count_newlines(&visitor.buffer),
"failed in format_file visitor.buffer:\n {:?}",
&visitor.buffer
);

@ytmimi ytmimi added the bug Panic, non-idempotency, invalid code, etc. label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

No branches or pull requests

2 participants