Skip to content

async drop cause ICE #140426

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

Open
Sherlock-Holo opened this issue Apr 29, 2025 · 4 comments
Open

async drop cause ICE #140426

Sherlock-Holo opened this issue Apr 29, 2025 · 4 comments
Labels
C-bug Category: This is a bug. F-async_drop `#![feature(async_drop)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Sherlock-Holo
Copy link

Code

#![feature(async_drop)]

use std::future::AsyncDrop;
use std::pin::Pin;

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let _st = St;
}

struct St;

impl AsyncDrop for St {
    async fn drop(self: Pin<&mut Self>) {
        println!("123");
    }
}

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (25cdf1f67 2025-04-28)
binary: rustc
commit-hash: 25cdf1f67463c9365d8d83778c933ec7480e940b
commit-date: 2025-04-28
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Error output

thread 'rustc' panicked at compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs:201:68:
index out of bounds: the len is 1 but the index is 1
stack backtrace:
   0:     0x796006a642e5 - std::backtrace::Backtrace::create::h5b5d29f0fcbef4c5
   1:     0x796004ef3855 - std::backtrace::Backtrace::force_capture::h46ea152eb057a4f7
   2:     0x796003f86011 - std[96024a80e4ce12a0]::panicking::update_hook::<alloc[703cfcb04acfdfda]::boxed::Box<rustc_driver_impl[a2bbb3d7e654019c]::install_ice_hook::{closure#1}>>::{closure#0}
   3:     0x796004f0d933 - std::panicking::rust_panic_with_hook::h7afddb00f409503c
   4:     0x796004f0d62a - std::panicking::begin_panic_handler::{{closure}}::h11311e14e26011d8
   5:     0x796004f098d9 - std::sys::backtrace::__rust_end_short_backtrace::h4a69b8a8bf83181b
   6:     0x796004f0d2ed - __rustc[ae73a5f87904751]::rust_begin_unwind
   7:     0x79600188d0d0 - core::panicking::panic_fmt::he7bfe01c5f8a6b92
   8:     0x7960033d8005 - core::panicking::panic_bounds_check::h60b2f61c06b46463
   9:     0x796003dd9633 - <core[6d7144d1d4266374]::iter::adapters::map::Map<core[6d7144d1d4266374]::iter::adapters::map::Map<core[6d7144d1d4266374]::ops::range::Range<usize>, <rustc_index[6fcb69c322e18028]::slice::IndexSlice<rustc_abi[16b420aafa014dd]::layout::ty::VariantIdx, rustc_abi[16b420aafa014dd]::LayoutData<rustc_abi[16b420aafa014dd]::layout::ty::FieldIdx, rustc_abi[16b420aafa014dd]::layout::ty::VariantIdx>>>::indices::{closure#0}>, rustc_codegen_llvm[4025aff5dfb5e881]::debuginfo::metadata::enums::native::build_coroutine_di_node::{closure#0}::{closure#0}> as core[6d7144d1d4266374]::iter::traits::iterator::Iterator>::next
  10:     0x796003e0681f - rustc_codegen_llvm[4025aff5dfb5e881]::debuginfo::metadata::enums::native::build_coroutine_di_node
  11:     0x796005d23bfd - rustc_codegen_llvm[4025aff5dfb5e881]::debuginfo::metadata::type_di_node
  12:     0x7960062b9372 - <rustc_codegen_llvm[4025aff5dfb5e881]::context::GenericCx<rustc_codegen_llvm[4025aff5dfb5e881]::context::FullCx> as rustc_codegen_ssa[8010b3f9fa421608]::traits::debuginfo::DebugInfoCodegenMethods>::dbg_scope_fn
  13:     0x796006645576 - rustc_codegen_ssa[8010b3f9fa421608]::mir::codegen_mir::<rustc_codegen_llvm[4025aff5dfb5e881]::builder::GenericBuilder<rustc_codegen_llvm[4025aff5dfb5e881]::context::FullCx>>
  14:     0x796006643d45 - rustc_codegen_llvm[4025aff5dfb5e881]::base::compile_codegen_unit::module_codegen
  15:     0x7960067dc4ec - <rustc_codegen_llvm[4025aff5dfb5e881]::LlvmCodegenBackend as rustc_codegen_ssa[8010b3f9fa421608]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  16:     0x7960067de2dc - <rustc_codegen_llvm[4025aff5dfb5e881]::LlvmCodegenBackend as rustc_codegen_ssa[8010b3f9fa421608]::traits::backend::CodegenBackend>::codegen_crate
  17:     0x79600658b29d - <rustc_interface[269edf8a537b00a5]::queries::Linker>::codegen_and_build_linker
  18:     0x79600658f46f - rustc_interface[269edf8a537b00a5]::passes::create_and_enter_global_ctxt::<core[6d7144d1d4266374]::option::Option<rustc_interface[269edf8a537b00a5]::queries::Linker>, rustc_driver_impl[a2bbb3d7e654019c]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  19:     0x7960066eceb9 - rustc_interface[269edf8a537b00a5]::interface::run_compiler::<(), rustc_driver_impl[a2bbb3d7e654019c]::run_compiler::{closure#0}>::{closure#1}
  20:     0x796006501728 - std[96024a80e4ce12a0]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[269edf8a537b00a5]::util::run_in_thread_with_globals<rustc_interface[269edf8a537b00a5]::util::run_in_thread_pool_with_globals<rustc_interface[269edf8a537b00a5]::interface::run_compiler<(), rustc_driver_impl[a2bbb3d7e654019c]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  21:     0x796006501b74 - <<std[96024a80e4ce12a0]::thread::Builder>::spawn_unchecked_<rustc_interface[269edf8a537b00a5]::util::run_in_thread_with_globals<rustc_interface[269edf8a537b00a5]::util::run_in_thread_pool_with_globals<rustc_interface[269edf8a537b00a5]::interface::run_compiler<(), rustc_driver_impl[a2bbb3d7e654019c]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[6d7144d1d4266374]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  22:     0x796006502f77 - std::sys::pal::unix::thread::Thread::new::thread_start::h7eeb46109c9d7745
  23:     0x7960004a3708 - <unknown>
  24:     0x796000527aac - <unknown>
  25:                0x0 - <unknown>


rustc version: 1.88.0-nightly (25cdf1f67 2025-04-28)
platform: x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
Backtrace

warning: `rust_learn` (lib) generated 10 warnings
   Compiling rust_learn v0.1.0 (/home/sherlock/git/rust_learn)
warning: the feature `async_drop` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:12
  |
1 | #![feature(async_drop)]
  |            ^^^^^^^^^^
  |
  = note: see issue #126482 <https://github.com/rust-lang/rust/issues/126482> for more information
  = note: `#[warn(incomplete_features)]` on by default


thread 'rustc' panicked at compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs:201:68:
index out of bounds: the len is 1 but the index is 1
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: <core::iter::adapters::map::Map<core::iter::adapters::map::Map<core::ops::range::Range<usize>, <rustc_index::slice::IndexSlice<rustc_abi::layout::ty::VariantIdx, rustc_abi::LayoutData<rustc_abi::layout::ty::FieldIdx, rustc_abi::layout::ty::VariantIdx>>>::indices::{closure#0}>, rustc_codegen_llvm::debuginfo::metadata::enums::native::build_coroutine_di_node::{closure#0}::{closure#0}> as core::iter::traits::iterator::Iterator>::next
   4: rustc_codegen_llvm::debuginfo::metadata::enums::native::build_coroutine_di_node
   5: rustc_codegen_llvm::debuginfo::metadata::type_di_node
   6: <rustc_codegen_llvm::context::GenericCx<rustc_codegen_llvm::context::FullCx> as rustc_codegen_ssa::traits::debuginfo::DebugInfoCodegenMethods>::dbg_scope_fn
   7: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::GenericBuilder<rustc_codegen_llvm::context::FullCx>>
   8: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
   9: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  10: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  11: <rustc_interface::queries::Linker>::codegen_and_build_linker
  12: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  13: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/home/sherlock/git/rust_learn/rustc-ice-2025-04-29T04_54_17-46614.txt` to your bug report

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C linker=clang -C incremental=[REDACTED] -C link-arg=-fuse-ld=mold -C target_cpu=x86-64-v2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
warning: `rust_learn` (bin "rust_learn") generated 1 warning
error: could not compile `rust_learn` (bin "rust_learn"); 1 warning emitted

Caused by:
  process didn't exit successfully: `/home/sherlock/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name rust_learn --edition=2024 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=145 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=fb7b476e0fb91d00 -C extra-filename=-93aff6a2681aca3a --out-dir /home/sherlock/git/rust_learn/target/debug/deps -C linker=clang -C incremental=/home/sherlock/git/rust_learn/target/debug/incremental -L dependency=/home/sherlock/git/rust_learn/target/debug/deps --extern anyhow=/home/sherlock/git/rust_learn/target/debug/deps/libanyhow-74d7e532cb662382.rlib --extern base64=/home/sherlock/git/rust_learn/target/debug/deps/libbase64-b2029bca7ba742fd.rlib --extern boringtun=/home/sherlock/git/rust_learn/target/debug/deps/libboringtun-fb8f467de899efca.rlib --extern bytes=/home/sherlock/git/rust_learn/target/debug/deps/libbytes-57c854b92fb36f5f.rlib --extern flume=/home/sherlock/git/rust_learn/target/debug/deps/libflume-94918a6a859e1ac7.rlib--extern futures_executor=/home/sherlock/git/rust_learn/target/debug/deps/libfutures_executor-56574f3565f22979.rlib --extern futures_util=/home/sherlock/git/rust_learn/target/debug/deps/libfutures_util-2f52708d7abfe127.rlib --extern ipnet=/home/sherlock/git/rust_learn/target/debug/deps/libipnet-254946b8fead8f77.rlib --extern iprange=/home/sherlock/git/rust_learn/target/debug/deps/libiprange-8cd98ef3265ffcb2.rlib --extern nix=/home/sherlock/git/rust_learn/target/debug/deps/libnix-fee0b09f6160ee7c.rlib --extern pnet_packet=/home/sherlock/git/rust_learn/target/debug/deps/libpnet_packet-90fb7050bfa37f43.rlib --extern quinn=/home/sherlock/git/rust_learn/target/debug/deps/libquinn-739b5bbc0f060e89.rlib --extern rand=/home/sherlock/git/rust_learn/target/debug/deps/librand-bdc15f51fdeab9dd.rlib --extern reqwest=/home/sherlock/git/rust_learn/target/debug/deps/libreqwest-f47bea0702c5c232.rlib --extern rtnetlink=/home/sherlock/git/rust_learn/target/debug/deps/librtnetlink-4e2782cdfb90bfcc.rlib --extern rust_learn=/home/sherlock/git/rust_learn/target/debug/deps/librust_learn-ec431fef5dc1d3f0.rlib --extern rustix=/home/sherlock/git/rust_learn/target/debug/deps/librustix-5b09b6145c82262d.rlib --extern rustls=/home/sherlock/git/rust_learn/target/debug/deps/librustls-8e844aeb78763f58.rlib --extern rustls_pemfile=/home/sherlock/git/rust_learn/target/debug/deps/librustls_pemfile-c67d38ca0c30ad21.rlib --extern tokio=/home/sherlock/git/rust_learn/target/debug/deps/libtokio-2f7727a06e5320e8.rlib --extern tun=/home/sherlock/git/rust_learn/target/debug/deps/libtun-ed284292b005c33b.rlib --extern zstd=/home/sherlock/git/rust_learn/target/debug/deps/libzstd-98787fde8924148c.rlib -C link-arg=-fuse-ld=mold -C target_cpu=x86-64-v2 -L native=/home/sherlock/git/rust_learn/target/debug/build/ring-0f8e4983219a3701/out -L native=/home/sherlock/git/rust_learn/target/debug/build/aws-lc-sys-0251f069c59f193d/out -L native=/home/sherlock/git/rust_learn/target/debug/build/zstd-sys-99c3c8f409528740/out` (exit status: 101)

@Sherlock-Holo Sherlock-Holo added 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. labels Apr 29, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 29, 2025
@petrochenkov petrochenkov added the F-async_drop `#![feature(async_drop)]` label Apr 29, 2025
@petrochenkov
Copy link
Contributor

cc @azhogin

@cyrgani
Copy link
Contributor

cyrgani commented Apr 29, 2025

simpler:

#![feature(async_drop)]
use std::task::Context;

fn f() -> Context<'static> {
    todo!()
}

fn main() {
    let mut body = Box::pin(async {});
    let _ = body.as_mut().poll(&mut f());
}

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 29, 2025
@moxian
Copy link
Contributor

moxian commented Apr 29, 2025

bisects to #123948
@rustbot label: +S-has-mcve +S-has-bisection +requires-incomplete-features

@rustbot rustbot added S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue requires-incomplete-features This issue requires the use of incomplete features. labels Apr 29, 2025
@azhogin
Copy link
Contributor

azhogin commented May 3, 2025

Fix: #140630
Also, impl Drop should also exist for impl AsyncDrop to work. Because there are some cases (unwind, drop in sync context), when async drop can't be used by compiler.

Zalathar added a commit to Zalathar/rust that referenced this issue May 4, 2025
…ource-info-fix, r=oli-obk

Async drop source info fix for proxy-drop-coroutine

Fixes crash at debug info generation: rust-lang#140426 .
Also, the submitted example requires sync Drop implementation too.
Because sync version is required for unwind and when drop is performed in sync context (sync function).

Probably, it is also needed to add such a lint/error about missed `impl Drop`, when there is `impl AsyncDrop`.

Fix description: even minimal, empty coroutine (for proxy-coroutine) has 3 states and the source info array should have 3 elements too.

```
#![feature(async_drop)]

use std::future::AsyncDrop;
use std::pin::Pin;

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let _st = St;
}

struct St;

impl AsyncDrop for St {
    async fn drop(self: Pin<&mut Self>) {
        println!("123");
    }
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-async_drop `#![feature(async_drop)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants