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: rustfmt: self.stashed_diagnostics.is_empty() #121450

Closed
matthiaskrgr opened this issue Feb 22, 2024 · 4 comments · Fixed by #121487
Closed

ICE: rustfmt: self.stashed_diagnostics.is_empty() #121450

matthiaskrgr opened this issue Feb 22, 2024 · 4 comments · Fixed by #121487
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-rustfmt Area: Rustfmt C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

#![u=||{static d=||1;}]

Meta

rustc --version --verbose:

rustfmt 1.7.0-nightly (f70f19f 2024-02-22)

Error output

rustfmt --check ./90873.rs --edition=2021

<output>
Backtrace

thread 'main' panicked at compiler/rustc_errors/src/lib.rs:565:9:
assertion failed: self.stashed_diagnostics.is_empty()
stack backtrace:
   0:     0x7f1bb03bbaf6 - std::backtrace_rs::backtrace::libunwind::trace::hef019eae7250a090
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f1bb03bbaf6 - std::backtrace_rs::backtrace::trace_unsynchronized::h163c9c558e7f1e4e
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f1bb03bbaf6 - std::sys_common::backtrace::_print_fmt::h84a7f2dbeae8e017
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f1bb03bbaf6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf7737af35c1403cd
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f1bb040ca7c - core::fmt::rt::Argument::fmt::h027f33016919ab54
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/core/src/fmt/rt.rs:142:9
   5:     0x7f1bb040ca7c - core::fmt::write::hed9b631feef55974
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f1bb03b04bf - std::io::Write::write_fmt::h3b1c8483aebfcef8
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/io/mod.rs:1846:15
   7:     0x7f1bb03bb8a4 - std::sys_common::backtrace::_print::h526b95c0b60f4650
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f1bb03bb8a4 - std::sys_common::backtrace::print::h3322d8b0a1d6207a
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f1bb03be5eb - std::panicking::default_hook::{{closure}}::h9f07e6147b1c8a2e
  10:     0x7f1bb03be339 - std::panicking::default_hook::h395b386ace4fbcb6
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/panicking.rs:292:9
  11:     0x7f1bad07073c - std[d26ecb90c771e100]::panicking::update_hook::<alloc[100d4e65626f4394]::boxed::Box<rustc_driver_impl[ab901dc85bea4c82]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f1bb03bed50 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h1a188bbe7a6bf646
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/alloc/src/boxed.rs:2030:9
  13:     0x7f1bb03bed50 - std::panicking::rust_panic_with_hook::h1eec7c1097026ee4
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/panicking.rs:786:13
  14:     0x7f1bb03bea59 - std::panicking::begin_panic_handler::{{closure}}::h4a05c0337f2d10b0
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/panicking.rs:652:13
  15:     0x7f1bb03bbfd6 - std::sys_common::backtrace::__rust_end_short_backtrace::h8e493856f2567f06
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f1bb03be7c4 - rust_begin_unwind
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/panicking.rs:648:5
  17:     0x7f1bb0408f95 - core::panicking::panic_fmt::h3ada378d4b3e4e06
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/core/src/panicking.rs:72:14
  18:     0x7f1bb0409053 - core::panicking::panic::hf686bd38e73a6fb0
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/core/src/panicking.rs:144:5
  19:     0x7f1baf9dd75b - <rustc_errors[e9339b16b54c0bc0]::DiagCtxtInner as core[17d6b7ce805ba05e]::ops::drop::Drop>::drop.cold.0
  20:     0x55d4e7044441 - core[17d6b7ce805ba05e]::ptr::drop_in_place::<rustc_errors[e9339b16b54c0bc0]::DiagCtxt>
  21:     0x55d4e712ae91 - <rustfmt_nightly[ae0384455389d0c6]::parse::session::ParseSess>::set_silent_emitter
  22:     0x55d4e6fc9264 - <rustfmt_nightly[ae0384455389d0c6]::Session<std[d26ecb90c771e100]::io::stdio::Stdout>>::format_input_inner::{closure#0}
  23:     0x55d4e6fdec61 - rustfmt[ed948694b77f896d]::format_and_emit_report::<std[d26ecb90c771e100]::io::stdio::Stdout>
  24:     0x55d4e6fdd0fc - rustfmt[ed948694b77f896d]::execute
  25:     0x55d4e6fd87cb - rustfmt[ed948694b77f896d]::main
  26:     0x55d4e6fc2eb3 - std[d26ecb90c771e100]::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  27:     0x55d4e6fc5159 - std[d26ecb90c771e100]::rt::lang_start::<()>::{closure#0}
  28:     0x7f1bb03a0f83 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h8f373a8093d54600
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/core/src/ops/function.rs:284:13
  29:     0x7f1bb03a0f83 - std::panicking::try::do_call::h5667b7fe242911ff
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/panicking.rs:555:40
  30:     0x7f1bb03a0f83 - std::panicking::try::h07c68af6ea9065e5
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/panicking.rs:519:19
  31:     0x7f1bb03a0f83 - std::panic::catch_unwind::h33d61217259ec2ad
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/panic.rs:142:14
  32:     0x7f1bb03a0f83 - std::rt::lang_start_internal::{{closure}}::h156787761fdc28fc
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/rt.rs:148:48
  33:     0x7f1bb03a0f83 - std::panicking::try::do_call::h7112e73550c147c3
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/panicking.rs:555:40
  34:     0x7f1bb03a0f83 - std::panicking::try::h88f707706bccf01e
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/panicking.rs:519:19
  35:     0x7f1bb03a0f83 - std::panic::catch_unwind::h10d08c1409151553
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/panic.rs:142:14
  36:     0x7f1bb03a0f83 - std::rt::lang_start_internal::h4d7e5d0f882473ac
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/rt.rs:148:20
  37:     0x55d4e6fdfe25 - main
  38:     0x7f1ba9e29d90 - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  39:     0x7f1ba9e29e40 - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:392:3
  40:     0x55d4e6fb2529 - <unknown>
  41:                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 `/home/gh-matthiaskrgr/vcs/github/glacier2/fixed/rustc-ice-2024-02-22T12_34_58-2399180.txt` to your bug report

query stack during panic:
end of query stack

@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-rustfmt Area: Rustfmt labels Feb 22, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 22, 2024
@matthiaskrgr
Copy link
Member Author

I suspect this is related to #121129 cc @nnethercote

@matthiaskrgr
Copy link
Member Author

tests/ui/suggestions/unnamable-types.rs

// Test that we do not suggest to add type annotations for unnamable types.

#![crate_type="lib"]
#![feature(coroutines)]

const A = 5;
//~^ ERROR: missing type for `const` item
//~| HELP: provide a type for the constant

static B: _ = "abc";
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static variables
//~| NOTE: not allowed in type signatures
//~| HELP: replace with the correct type


// FIXME: this should also suggest a function pointer, as the closure is non-capturing
const C: _ = || 42;
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for constants
//~| NOTE: not allowed in type signatures
//~| NOTE: however, the inferred type

struct S<T> { t: T }
const D = S { t: { let i = 0; move || -> i32 { i } } };
//~^ ERROR: missing type for `const` item
//~| NOTE: however, the inferred type


fn foo() -> i32 { 42 }
const E = foo;
//~^ ERROR: missing type for `const` item
//~| HELP: provide a type for the constant
const F = S { t: foo };
//~^ ERROR: missing type for `const` item
//~| HELP: provide a type for the constant


const G = || -> i32 { yield 0; return 1; };
//~^ ERROR: missing type for `const` item
//~| NOTE: however, the inferred type

@nnethercote nnethercote self-assigned this Feb 22, 2024
@nnethercote
Copy link
Contributor

I suspect this is related to #121129 cc @nnethercote

Very likely. I'll take a look soon.

nnethercote added a commit to nnethercote/rust that referenced this issue Feb 23, 2024
Commit 72b172b in rust-lang#121206 changed things so that
`emit_stashed_diagnostics` is only called from `run_compiler`. But
rustfmt doesn't use `run_compiler`, so it needs to call
`emit_stashed_diagnostics` itself to avoid an abort in
`DiagCtxtInner::drop` when stashed diagnostics occur.

Fixes rust-lang#121450.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 23, 2024
Explicitly call `emit_stashed_diagnostics`.

Commit 72b172b in rust-lang#121206 changed things so that
`emit_stashed_diagnostics` is only called from `run_compiler`. But rustfmt doesn't use `run_compiler`, so it needs to call `emit_stashed_diagnostics` itself to avoid an abort in `DiagCtxtInner::drop` when stashed diagnostics occur.

Fixes rust-lang#121450.

r? `@oli-obk`
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 23, 2024
Rollup merge of rust-lang#121487 - nnethercote:fix-121450, r=oli-obk

Explicitly call `emit_stashed_diagnostics`.

Commit 72b172b in rust-lang#121206 changed things so that
`emit_stashed_diagnostics` is only called from `run_compiler`. But rustfmt doesn't use `run_compiler`, so it needs to call `emit_stashed_diagnostics` itself to avoid an abort in `DiagCtxtInner::drop` when stashed diagnostics occur.

Fixes rust-lang#121450.

r? `@oli-obk`
@saethlin saethlin added A-diagnostics Area: Messages for errors, warnings, and lints and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 25, 2024
@nnethercote
Copy link
Contributor

I suspect this is related to #121129 cc @nnethercote

For the record: it was #121206 that caused this.

calebcartwright pushed a commit to calebcartwright/rust that referenced this issue Jun 22, 2024
Commit 72b172b in rust-lang#121206 changed things so that
`emit_stashed_diagnostics` is only called from `run_compiler`. But
rustfmt doesn't use `run_compiler`, so it needs to call
`emit_stashed_diagnostics` itself to avoid an abort in
`DiagCtxtInner::drop` when stashed diagnostics occur.

Fixes rust-lang#121450.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-rustfmt Area: Rustfmt C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants