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

async lambda with capture ICE #127012

Closed
facundo-villa opened this issue Jun 27, 2024 · 4 comments · Fixed by #127136
Closed

async lambda with capture ICE #127012

facundo-villa opened this issue Jun 27, 2024 · 4 comments · Fixed by #127136
Assignees
Labels
C-bug Category: This is a bug. F-async_closure `#![feature(async_closure)]` 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

@facundo-villa
Copy link

Code

#![feature(async_closure)]

use futures::future::join_all;

async fn fun<'a>(param: &'a u32) {
	let elems = vec![1, 2, 3];

	let _ = join_all(elems.iter().map(async |v: &u32| {
		format!("{}", param + v)
	})).await;
}

fn main() {
	futures::executor::block_on(fun(&1));
}

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (bcf94dec5 2024-06-23)
binary: rustc
commit-hash: bcf94dec5ba6838e435902120c0384c360126a26
commit-date: 2024-06-23
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

thread 'rustc' panicked at compiler/rustc_mir_transform/src/shim.rs:1036:9:
assertion `left == right` failed
  left: (&'{erased} &'{erased} u32,)
 right: ()
stack backtrace:
   0:     0x7a291c388535 - std::backtrace_rs::backtrace::libunwind::trace::hd0a431ec4286eec2
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7a291c388535 - std::backtrace_rs::backtrace::trace_unsynchronized::h55b7147bbdcae103
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7a291c388535 - std::sys::backtrace::_print_fmt::h5ba811d5fa76665c
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/std/src/sys/backtrace.rs:68:5
   3:     0x7a291c388535 - <std::sys::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc7ed570e71131300
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/std/src/sys/backtrace.rs:44:22
   4:     0x7a291c3d7fbb - core::fmt::rt::Argument::fmt::hd5f04252949343fb
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/core/src/fmt/rt.rs:165:63
   5:     0x7a291c3d7fbb - core::fmt::write::h525edfe35df838b2
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/core/src/fmt/mod.rs:1168:21
   6:     0x7a291c37d0df - std::io::Write::write_fmt::h7ca43b42bd752649
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/std/src/io/mod.rs:1835:15
   7:     0x7a291c38830e - std::sys::backtrace::_print::h5374f6e608e081ce
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/std/src/sys/backtrace.rs:47:5
   8:     0x7a291c38830e - std::sys::backtrace::print::ha7453f9fb23375ba
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/std/src/sys/backtrace.rs:34:9
   9:     0x7a291c38ad49 - std::panicking::default_hook::{{closure}}::hf9505cfe32528ed7
  10:     0x7a291c38aaec - std::panicking::default_hook::ha7962b8515cde474
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/std/src/panicking.rs:292:9
  11:     0x7a29189dd61f - std[3133fd9b3ece806f]::panicking::update_hook::<alloc[6345b4e04555f913]::boxed::Box<rustc_driver_impl[6d6ee7a70b9321e3]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7a291c38b61f - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h50adda42383ad1db
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/alloc/src/boxed.rs:2078:9
  13:     0x7a291c38b61f - std::panicking::rust_panic_with_hook::hea4c878dc07df55b
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/std/src/panicking.rs:804:13
  14:     0x7a291c38b247 - std::panicking::begin_panic_handler::{{closure}}::hca858b01da723ad6
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/std/src/panicking.rs:670:13
  15:     0x7a291c3889f9 - std::sys::backtrace::__rust_end_short_backtrace::h94b285c94ce95409
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/std/src/sys/backtrace.rs:171:18
  16:     0x7a291c38af24 - rust_begin_unwind
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/std/src/panicking.rs:661:5
  17:     0x7a291c3d4573 - core::panicking::panic_fmt::h47b1e0ddaafb858d
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/core/src/panicking.rs:74:14
  18:     0x7a291c3d4a7e - core::panicking::assert_failed_inner::he9b3e9b46d45eb2f
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/core/src/panicking.rs:410:17
  19:     0x7a291911c8a3 - core[7edf950208aeea0d]::panicking::assert_failed::<rustc_middle[b31a38de10a3401e]::ty::Ty, rustc_middle[b31a38de10a3401e]::ty::Ty>
  20:     0x7a291aaaa155 - rustc_mir_transform[70366f811ccd75]::shim::make_shim
  21:     0x7a291aaa6eef - rustc_query_impl[cf7ab296789b2a81]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cf7ab296789b2a81]::query_impl::mir_shims::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b31a38de10a3401e]::query::erase::Erased<[u8; 8usize]>>
  22:     0x7a291aaa6eb9 - <rustc_query_impl[cf7ab296789b2a81]::query_impl::mir_shims::dynamic_query::{closure#2} as core[7edf950208aeea0d]::ops::function::FnOnce<(rustc_middle[b31a38de10a3401e]::ty::context::TyCtxt, rustc_middle[b31a38de10a3401e]::ty::instance::InstanceKind)>>::call_once
  23:     0x7a291a33713b - <rustc_query_system[a3209a28ddb0c6f4]::query::plumbing::execute_job_incr<rustc_query_impl[cf7ab296789b2a81]::DynamicConfig<rustc_query_system[a3209a28ddb0c6f4]::query::caches::DefaultCache<rustc_middle[b31a38de10a3401e]::ty::instance::InstanceKind, rustc_middle[b31a38de10a3401e]::query::erase::Erased<[u8; 4usize]>>, false, false, false>, rustc_query_impl[cf7ab296789b2a81]::plumbing::QueryCtxt>::{closure#2}::{closure#2} as core[7edf950208aeea0d]::ops::function::FnOnce<((rustc_query_impl[cf7ab296789b2a81]::plumbing::QueryCtxt, rustc_query_impl[cf7ab296789b2a81]::DynamicConfig<rustc_query_system[a3209a28ddb0c6f4]::query::caches::DefaultCache<rustc_middle[b31a38de10a3401e]::ty::instance::InstanceKind, rustc_middle[b31a38de10a3401e]::query::erase::Erased<[u8; 4usize]>>, false, false, false>), rustc_middle[b31a38de10a3401e]::ty::instance::InstanceKind)>>::call_once
  24:     0x7a291acd4438 - rustc_query_system[a3209a28ddb0c6f4]::query::plumbing::try_execute_query::<rustc_query_impl[cf7ab296789b2a81]::DynamicConfig<rustc_query_system[a3209a28ddb0c6f4]::query::caches::DefaultCache<rustc_middle[b31a38de10a3401e]::ty::instance::InstanceKind, rustc_middle[b31a38de10a3401e]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[cf7ab296789b2a81]::plumbing::QueryCtxt, true>
  25:     0x7a291acd3d26 - rustc_query_impl[cf7ab296789b2a81]::query_impl::mir_shims::get_query_incr::__rust_end_short_backtrace
  26:     0x7a291a87d6e9 - <rustc_middle[b31a38de10a3401e]::ty::context::TyCtxt>::instance_mir
  27:     0x7a291aea211a - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec::{closure#0}
  28:     0x7a291a0dd96f - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  29:     0x7a291a0de0ec - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  30:     0x7a291a0de0ec - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  31:     0x7a291a0de0ec - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  32:     0x7a291a0de0ec - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  33:     0x7a291a0de0ec - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  34:     0x7a291a0de0ec - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  35:     0x7a291a0de0ec - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  36:     0x7a291a0de0ec - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  37:     0x7a291a0de0ec - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  38:     0x7a291a0de0ec - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  39:     0x7a291a0de0ec - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  40:     0x7a291a0de0ec - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  41:     0x7a291a0de0ec - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  42:     0x7a291a0de0ec - rustc_monomorphize[2e477236252b8d74]::collector::collect_items_rec
  43:     0x7a291a4ff9ad - rustc_monomorphize[2e477236252b8d74]::partitioning::collect_and_partition_mono_items
  44:     0x7a291ae77064 - rustc_query_impl[cf7ab296789b2a81]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cf7ab296789b2a81]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b31a38de10a3401e]::query::erase::Erased<[u8; 24usize]>>
  45:     0x7a291ae77049 - <rustc_query_impl[cf7ab296789b2a81]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[7edf950208aeea0d]::ops::function::FnOnce<(rustc_middle[b31a38de10a3401e]::ty::context::TyCtxt, ())>>::call_once
  46:     0x7a291ae97b9a - rustc_query_system[a3209a28ddb0c6f4]::query::plumbing::try_execute_query::<rustc_query_impl[cf7ab296789b2a81]::DynamicConfig<rustc_query_system[a3209a28ddb0c6f4]::query::caches::SingleCache<rustc_middle[b31a38de10a3401e]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[cf7ab296789b2a81]::plumbing::QueryCtxt, true>
  47:     0x7a291ae974ca - rustc_query_impl[cf7ab296789b2a81]::query_impl::collect_and_partition_mono_items::get_query_incr::__rust_end_short_backtrace
  48:     0x7a291af766ef - <rustc_codegen_llvm[eea28e6f6670a8c2]::LlvmCodegenBackend as rustc_codegen_ssa[73d9873bb1e453d6]::traits::backend::CodegenBackend>::codegen_crate
  49:     0x7a291af15245 - rustc_interface[90e33289a2c95a72]::passes::start_codegen
  50:     0x7a291af148da - <rustc_interface[90e33289a2c95a72]::queries::Queries>::codegen_and_build_linker
  51:     0x7a291adab3c2 - rustc_interface[90e33289a2c95a72]::interface::run_compiler::<core[7edf950208aeea0d]::result::Result<(), rustc_span[44ab5cd48158b41]::ErrorGuaranteed>, rustc_driver_impl[6d6ee7a70b9321e3]::run_compiler::{closure#0}>::{closure#1}
  52:     0x7a291ad2e589 - std[3133fd9b3ece806f]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[90e33289a2c95a72]::util::run_in_thread_with_globals<rustc_interface[90e33289a2c95a72]::util::run_in_thread_pool_with_globals<rustc_interface[90e33289a2c95a72]::interface::run_compiler<core[7edf950208aeea0d]::result::Result<(), rustc_span[44ab5cd48158b41]::ErrorGuaranteed>, rustc_driver_impl[6d6ee7a70b9321e3]::run_compiler::{closure#0}>::{closure#1}, core[7edf950208aeea0d]::result::Result<(), rustc_span[44ab5cd48158b41]::ErrorGuaranteed>>::{closure#0}, core[7edf950208aeea0d]::result::Result<(), rustc_span[44ab5cd48158b41]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7edf950208aeea0d]::result::Result<(), rustc_span[44ab5cd48158b41]::ErrorGuaranteed>>
  53:     0x7a291ad2e33a - <<std[3133fd9b3ece806f]::thread::Builder>::spawn_unchecked_<rustc_interface[90e33289a2c95a72]::util::run_in_thread_with_globals<rustc_interface[90e33289a2c95a72]::util::run_in_thread_pool_with_globals<rustc_interface[90e33289a2c95a72]::interface::run_compiler<core[7edf950208aeea0d]::result::Result<(), rustc_span[44ab5cd48158b41]::ErrorGuaranteed>, rustc_driver_impl[6d6ee7a70b9321e3]::run_compiler::{closure#0}>::{closure#1}, core[7edf950208aeea0d]::result::Result<(), rustc_span[44ab5cd48158b41]::ErrorGuaranteed>>::{closure#0}, core[7edf950208aeea0d]::result::Result<(), rustc_span[44ab5cd48158b41]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7edf950208aeea0d]::result::Result<(), rustc_span[44ab5cd48158b41]::ErrorGuaranteed>>::{closure#2} as core[7edf950208aeea0d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  54:     0x7a291c3954ab - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hfc3ada08a889a9bc
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/alloc/src/boxed.rs:2064:9
  55:     0x7a291c3954ab - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hbb39fc60220405ae
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/alloc/src/boxed.rs:2064:9
  56:     0x7a291c3954ab - std::sys::pal::unix::thread::Thread::new::thread_start::h89fc10007e0b01e6
                               at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/std/src/sys/pal/unix/thread.rs:108:17
  57:     0x7a2915294ac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  58:     0x7a2915326850 - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  59:                0x0 - <unknown>

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/facundovilla/development/error/error/rustc-ice-2024-06-27T03_37_47-57619.txt` to your bug report

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
#0 [mir_shims] generating MIR shim for `fun::{closure#0}::{closure#0}`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `error` (bin "error")
Backtrace

thread 'rustc' panicked at compiler/rustc_mir_transform/src/shim.rs:1036:9:
assertion `left == right` failed
  left: (&'{erased} &'{erased} u32,)
 right: ()
stack backtrace:
   0: rust_begin_unwind
             at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/std/src/panicking.rs:661:5
   1: core::panicking::panic_fmt
             at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/core/src/panicking.rs:74:14
   2: core::panicking::assert_failed_inner
             at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/library/core/src/panicking.rs:410:17
   3: core::panicking::assert_failed::<rustc_middle::ty::Ty, rustc_middle::ty::Ty>
   4: rustc_mir_transform::shim::make_shim
      [... omitted 3 frames ...]
   5: <rustc_middle::ty::context::TyCtxt>::instance_mir
   6: rustc_monomorphize::collector::collect_items_rec::{closure#0}
   7: rustc_monomorphize::collector::collect_items_rec
   8: rustc_monomorphize::collector::collect_items_rec
   9: rustc_monomorphize::collector::collect_items_rec
  10: rustc_monomorphize::collector::collect_items_rec
  11: rustc_monomorphize::collector::collect_items_rec
  12: rustc_monomorphize::collector::collect_items_rec
  13: rustc_monomorphize::collector::collect_items_rec
  14: rustc_monomorphize::collector::collect_items_rec
  15: rustc_monomorphize::collector::collect_items_rec
  16: rustc_monomorphize::collector::collect_items_rec
  17: rustc_monomorphize::collector::collect_items_rec
  18: rustc_monomorphize::collector::collect_items_rec
  19: rustc_monomorphize::collector::collect_items_rec
  20: rustc_monomorphize::collector::collect_items_rec
  21: rustc_monomorphize::collector::collect_items_rec
  22: rustc_monomorphize::partitioning::collect_and_partition_mono_items
      [... omitted 2 frames ...]
  23: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  24: rustc_interface::passes::start_codegen
  25: <rustc_interface::queries::Queries>::codegen_and_build_linker
  26: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, 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/facundovilla/development/error/error/rustc-ice-2024-06-27T03_41_44-61947.txt` to your bug report

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
#0 [mir_shims] generating MIR shim for `fun::{closure#0}::{closure#0}`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `error` (bin "error")

I managed to recreate this issue but I still need the `futures` crate.
@facundo-villa facundo-villa 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 Jun 27, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 27, 2024
@facundo-villa
Copy link
Author

It can also be triggered like this.

#![feature(async_closure)]

use futures::future::join_all;

async fn fun<'a>(param: &'a u32) {
	let _ = join_all((0..3).map(async |_| {
		format!("{}", param)
	})).await;
}

fn main() {
	futures::executor::block_on(fun(&1));
}

@theemathas
Copy link
Contributor

Minimized:

#![feature(async_closure)]

// Only Fn and FnMut cause an ICE. FnOnce doesn't.
fn call<T>(mut f: impl FnMut() -> T) {
    f();  // Discard the returned future. No await needed for ICE.
}

fn main() {
    let x = 1_i32;
    call(async || x);
}
Error output
   Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at compiler/rustc_mir_transform/src/shim.rs:1036:9:
assertion `left == right` failed
  left: (&'{erased} i32,)
 right: ()
stack backtrace:
   0:     0x7f8dd091b515 - std::backtrace_rs::backtrace::libunwind::trace::h3e6ef95ba444c071
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7f8dd091b515 - std::backtrace_rs::backtrace::trace_unsynchronized::hf308e5cf23ddb1f2
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f8dd091b515 - std::sys::backtrace::_print_fmt::h875f055a8443612e
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/sys/backtrace.rs:68:5
   3:     0x7f8dd091b515 - <std::sys::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf048241184006193
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/sys/backtrace.rs:44:22
   4:     0x7f8dd096ae7b - core::fmt::rt::Argument::fmt::hbfa8b610cdf08154
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/core/src/fmt/rt.rs:165:63
   5:     0x7f8dd096ae7b - core::fmt::write::h38ac925a86684a19
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/core/src/fmt/mod.rs:1168:21
   6:     0x7f8dd09100bf - std::io::Write::write_fmt::h8e14b1bbba4ad770
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/io/mod.rs:1835:15
   7:     0x7f8dd091b2ee - std::sys::backtrace::_print::heb4ac079ec90a68e
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/sys/backtrace.rs:47:5
   8:     0x7f8dd091b2ee - std::sys::backtrace::print::ha33f33bac52a4063
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/sys/backtrace.rs:34:9
   9:     0x7f8dd091dc39 - std::panicking::default_hook::{{closure}}::h2144f34920a14974
  10:     0x7f8dd091d9dc - std::panicking::default_hook::h18933871d80cdc21
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/panicking.rs:292:9
  11:     0x7f8dd3d6f4a0 - std[20db51b4dc66b481]::panicking::update_hook::<alloc[7a9d83151868560e]::boxed::Box<rustc_driver_impl[42aec5b3602e6800]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f8dd091e50f - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h1cfdd0f28ef5545b
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/alloc/src/boxed.rs:2078:9
  13:     0x7f8dd091e50f - std::panicking::rust_panic_with_hook::h4ad51c0c6b25b444
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/panicking.rs:804:13
  14:     0x7f8dd091e137 - std::panicking::begin_panic_handler::{{closure}}::h3425c28d75ee8072
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/panicking.rs:670:13
  15:     0x7f8dd091b9d9 - std::sys::backtrace::__rust_end_short_backtrace::h1e8092621577272d
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/sys/backtrace.rs:171:18
  16:     0x7f8dd091de14 - rust_begin_unwind
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/panicking.rs:661:5
  17:     0x7f8dd0967433 - core::panicking::panic_fmt::hee696384dfa25c0c
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/core/src/panicking.rs:74:14
  18:     0x7f8dd096793e - core::panicking::assert_failed_inner::hbe69f7ee81ff4d1a
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/core/src/panicking.rs:410:17
  19:     0x7f8dd44b0a03 - core[fd5e850c33eb6236]::panicking::assert_failed::<rustc_middle[b588a4788bcf8236]::ty::Ty, rustc_middle[b588a4788bcf8236]::ty::Ty>
  20:     0x7f8dd5ea2aab - rustc_mir_transform[fdf71a3a69b9138a]::shim::make_shim
  21:     0x7f8dd5e9f8ef - rustc_query_impl[33da1f1d673ac58e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[33da1f1d673ac58e]::query_impl::mir_shims::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b588a4788bcf8236]::query::erase::Erased<[u8; 8usize]>>
  22:     0x7f8dd5e9f8b9 - <rustc_query_impl[33da1f1d673ac58e]::query_impl::mir_shims::dynamic_query::{closure#2} as core[fd5e850c33eb6236]::ops::function::FnOnce<(rustc_middle[b588a4788bcf8236]::ty::context::TyCtxt, rustc_middle[b588a4788bcf8236]::ty::instance::InstanceKind)>>::call_once
  23:     0x7f8dd56d4e4f - rustc_query_system[32abc7d9028ee329]::query::plumbing::try_execute_query::<rustc_query_impl[33da1f1d673ac58e]::DynamicConfig<rustc_query_system[32abc7d9028ee329]::query::caches::DefaultCache<rustc_middle[b588a4788bcf8236]::ty::instance::InstanceKind, rustc_middle[b588a4788bcf8236]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[33da1f1d673ac58e]::plumbing::QueryCtxt, false>
  24:     0x7f8dd56d4bb9 - rustc_query_impl[33da1f1d673ac58e]::query_impl::mir_shims::get_query_non_incr::__rust_end_short_backtrace
  25:     0x7f8dd5b9780d - <rustc_middle[b588a4788bcf8236]::ty::context::TyCtxt>::instance_mir
  26:     0x7f8dd6210e9a - rustc_monomorphize[12e0af1616a24b7e]::collector::collect_items_rec::{closure#0}
  27:     0x7f8dd546d9af - rustc_monomorphize[12e0af1616a24b7e]::collector::collect_items_rec
  28:     0x7f8dd546e12c - rustc_monomorphize[12e0af1616a24b7e]::collector::collect_items_rec
  29:     0x7f8dd546e12c - rustc_monomorphize[12e0af1616a24b7e]::collector::collect_items_rec
  30:     0x7f8dd56530ad - rustc_monomorphize[12e0af1616a24b7e]::partitioning::collect_and_partition_mono_items
  31:     0x7f8dd61fa664 - rustc_query_impl[33da1f1d673ac58e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[33da1f1d673ac58e]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b588a4788bcf8236]::query::erase::Erased<[u8; 24usize]>>
  32:     0x7f8dd61fa649 - <rustc_query_impl[33da1f1d673ac58e]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[fd5e850c33eb6236]::ops::function::FnOnce<(rustc_middle[b588a4788bcf8236]::ty::context::TyCtxt, ())>>::call_once
  33:     0x7f8dd61fa208 - rustc_query_system[32abc7d9028ee329]::query::plumbing::try_execute_query::<rustc_query_impl[33da1f1d673ac58e]::DynamicConfig<rustc_query_system[32abc7d9028ee329]::query::caches::SingleCache<rustc_middle[b588a4788bcf8236]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[33da1f1d673ac58e]::plumbing::QueryCtxt, false>
  34:     0x7f8dd61f9f21 - rustc_query_impl[33da1f1d673ac58e]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7f8dd631172f - <rustc_codegen_llvm[f77607e41541149f]::LlvmCodegenBackend as rustc_codegen_ssa[a768f5e0bba2f7a]::traits::backend::CodegenBackend>::codegen_crate
  36:     0x7f8dd6297a45 - rustc_interface[d19dc351f3fbc095]::passes::start_codegen
  37:     0x7f8dd62970da - <rustc_interface[d19dc351f3fbc095]::queries::Queries>::codegen_and_build_linker
  38:     0x7f8dd61269c2 - rustc_interface[d19dc351f3fbc095]::interface::run_compiler::<core[fd5e850c33eb6236]::result::Result<(), rustc_span[f8da6251a5b957ab]::ErrorGuaranteed>, rustc_driver_impl[42aec5b3602e6800]::run_compiler::{closure#0}>::{closure#1}
  39:     0x7f8dd6074d89 - std[20db51b4dc66b481]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[d19dc351f3fbc095]::util::run_in_thread_with_globals<rustc_interface[d19dc351f3fbc095]::util::run_in_thread_pool_with_globals<rustc_interface[d19dc351f3fbc095]::interface::run_compiler<core[fd5e850c33eb6236]::result::Result<(), rustc_span[f8da6251a5b957ab]::ErrorGuaranteed>, rustc_driver_impl[42aec5b3602e6800]::run_compiler::{closure#0}>::{closure#1}, core[fd5e850c33eb6236]::result::Result<(), rustc_span[f8da6251a5b957ab]::ErrorGuaranteed>>::{closure#0}, core[fd5e850c33eb6236]::result::Result<(), rustc_span[f8da6251a5b957ab]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[fd5e850c33eb6236]::result::Result<(), rustc_span[f8da6251a5b957ab]::ErrorGuaranteed>>
  40:     0x7f8dd6074b3a - <<std[20db51b4dc66b481]::thread::Builder>::spawn_unchecked_<rustc_interface[d19dc351f3fbc095]::util::run_in_thread_with_globals<rustc_interface[d19dc351f3fbc095]::util::run_in_thread_pool_with_globals<rustc_interface[d19dc351f3fbc095]::interface::run_compiler<core[fd5e850c33eb6236]::result::Result<(), rustc_span[f8da6251a5b957ab]::ErrorGuaranteed>, rustc_driver_impl[42aec5b3602e6800]::run_compiler::{closure#0}>::{closure#1}, core[fd5e850c33eb6236]::result::Result<(), rustc_span[f8da6251a5b957ab]::ErrorGuaranteed>>::{closure#0}, core[fd5e850c33eb6236]::result::Result<(), rustc_span[f8da6251a5b957ab]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[fd5e850c33eb6236]::result::Result<(), rustc_span[f8da6251a5b957ab]::ErrorGuaranteed>>::{closure#2} as core[fd5e850c33eb6236]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7f8dd092839b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h94ad910a99affeba
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/alloc/src/boxed.rs:2064:9
  42:     0x7f8dd092839b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he514aef6ea70403a
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/alloc/src/boxed.rs:2064:9
  43:     0x7f8dd092839b - std::sys::pal::unix::thread::Thread::new::thread_start::hf130b2754bc7a5a1
                               at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/sys/pal/unix/thread.rs:108:17
  44:     0x7f8dd0832609 - start_thread
  45:     0x7f8dd0755353 - clone
  46:                0x0 - <unknown>

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 `/playground/rustc-ice-2024-06-27T04_35_35-936.txt` to your bug report

note: compiler flags: --crate-type bin -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

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

query stack during panic:
#0 [mir_shims] generating MIR shim for `main::{closure#0}`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `playground` (bin "playground")

@theemathas
Copy link
Contributor

Note: In the original code, changing async |v: &u32| { to |v: &u32| async move { causes the code to compile.

@GrigorenkoPV
Copy link
Contributor

Minimized:

#![feature(async_closure)]

// Only Fn and FnMut cause an ICE. FnOnce doesn't.
fn call<T>(mut f: impl FnMut() -> T) {
    f();  // Discard the returned future. No await needed for ICE.
}

fn main() {
    let x = 1_i32;
    call(async || x);
}

Regression in #125259

@compiler-errors compiler-errors self-assigned this Jun 29, 2024
@compiler-errors compiler-errors added the F-async_closure `#![feature(async_closure)]` label Jun 29, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 2, 2024
…v-shim, r=oli-obk

Fix `FnMut::call_mut`/`Fn::call` shim for async closures that capture references

I adjusted async closures to be able to implement `Fn` and `FnMut` *even if* they capture references, as long as those references did not need to borrow data from the closure captures themselves. See rust-lang#125259.

However, when I did this, I didn't actually relax an assertion in the `build_construct_coroutine_by_move_shim` shim code, which builds the `Fn`/`FnMut`/`FnOnce` implementations for async closures. Therefore, if we actually tried to *call* `FnMut`/`Fn` on async closures, it would ICE.

This PR adjusts this assertion to ensure that we only capture immutable references in closures if they implement `Fn`/`FnMut`. It also adds a bunch of tests and makes more of the async-closure tests into `build-pass` since we often care about these tests actually generating the right closure shims and stuff. I think it might be excessive to *always* use build-pass here, but 🤷 it's not that big of a deal.

Fixes rust-lang#127019
Fixes rust-lang#127012

r? oli-obk
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 2, 2024
…v-shim, r=oli-obk

Fix `FnMut::call_mut`/`Fn::call` shim for async closures that capture references

I adjusted async closures to be able to implement `Fn` and `FnMut` *even if* they capture references, as long as those references did not need to borrow data from the closure captures themselves. See rust-lang#125259.

However, when I did this, I didn't actually relax an assertion in the `build_construct_coroutine_by_move_shim` shim code, which builds the `Fn`/`FnMut`/`FnOnce` implementations for async closures. Therefore, if we actually tried to *call* `FnMut`/`Fn` on async closures, it would ICE.

This PR adjusts this assertion to ensure that we only capture immutable references in closures if they implement `Fn`/`FnMut`. It also adds a bunch of tests and makes more of the async-closure tests into `build-pass` since we often care about these tests actually generating the right closure shims and stuff. I think it might be excessive to *always* use build-pass here, but 🤷 it's not that big of a deal.

Fixes rust-lang#127019
Fixes rust-lang#127012

r? oli-obk
@bors bors closed this as completed in 3cf567e Jul 2, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 4, 2024
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_closure `#![feature(async_closure)]` 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.

6 participants