Description
Code
This bug only happens when calling a method on two different referenced variables inside an async closure. For some reason, this bug will not happen if the lines are flipped (calling it on test first then temp). It also will not happen if test isn't cloned outside the closure first.
This will error:
#![feature(async_closure, async_fn_traits)]
fn main() {}
pub fn test(test: &u64, temp: &u64) {
let test = test.clone();
async || {
temp.abs_diff(12);
test.clone();
};
}
This will not:
pub fn test(test: &u64, temp: &u64) {
async || {
temp.abs_diff(12);
test.clone();
};
}
Neither will:
pub fn test(test: &u64, temp: &u64) {
let test = test.clone();
async || {
test.clone();
temp.abs_diff(12);
};
}
Nor will:
pub fn test(test: &u64, temp: &u64) {
let temp = temp.clone();
async || {
test.clone();
temp.abs_diff(12);
};
}
But if both the order is flipped and the line order is flipped it will crash (variable name changed to make sure shadowing wasn't the issue):
pub fn test(test: &u64, temp: &u64) {
let other = test.clone();
async || {
temp.clone();
other.abs_diff(12);
};
}
This setup for the bug was found entirely through trial and error. The original issue was found in a nightly build of a project I'm working on (https://github.com/BigBadE/Raven-Language/actions/runs/8608806965/job/23628381189).
Meta
This bug was introduced in the latest version of nightly (2024-04-08). It was not present in 2024-04-07.
rustc 1.79.0-nightly (ab5bda1 2024-04-08)
binary: rustc
commit-hash: ab5bda1
commit-date: 2024-04-08
host: x86_64-pc-windows-msvc
release: 1.79.0-nightly
LLVM version: 18.1.3
Error output
$ cargo build
Compiling testing v0.1.0 (D:\RustProjects\testing)
thread 'rustc' panicked at compiler\rustc_mir_transform\src\coroutine\by_move_body.rs:159:17:
assertion failed: child_capture.place.projections.len() >=
parent_capture.place.projections.len()
stack backtrace:
0: 0x7ff8165537fa - std::backtrace_rs::backtrace::dbghelp64::trace
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:99
1: 0x7ff8165537fa - std::backtrace_rs::backtrace::trace_unsynchronized
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
2: 0x7ff8165537fa - std::sys_common::backtrace::_print_fmt
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\std\src\sys_common\backtrace.rs:68
3: 0x7ff8165537fa - std::sys_common::backtrace::_print::impl$0::fmt
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\std\src\sys_common\backtrace.rs:44
4: 0x7ff8165845e9 - core::fmt::rt::Argument::fmt
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\core\src\fmt\rt.rs:142
5: 0x7ff8165845e9 - core::fmt::write
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\core\src\fmt\mod.rs:1153
6: 0x7ff816549fd1 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\std\src\io\mod.rs:1843
7: 0x7ff8165535e6 - std::sys_common::backtrace::print
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\std\src\sys_common\backtrace.rs:34
8: 0x7ff8165567f8 - std::panicking::default_hook::closure$1
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\std\src\panicking.rs:271
9: 0x7ff81655643a - std::panicking::default_hook
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\std\src\panicking.rs:291
10: 0x7fffd42bb030 - __longjmp_internal
11: 0x7ff816556e3c - alloc::boxed::impl$50::call
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\alloc\src\boxed.rs:2032
12: 0x7ff816556e3c - std::panicking::rust_panic_with_hook
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\std\src\panicking.rs:792
13: 0x7ff816556c8b - std::panicking::begin_panic_handler::closure$0
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\std\src\panicking.rs:649
14: 0x7ff81655410f - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\std\src\sys_common\backtrace.rs:171
15: 0x7ff816556978 - std::panicking::begin_panic_handler
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\std\src\panicking.rs:645
16: 0x7ff8165acae7 - core::panicking::panic_fmt
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\core\src\panicking.rs:72
17: 0x7ff8165acbc0 - core::panicking::panic
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\core\src\panicking.rs:141
18: 0x7fffd323ecd2 - <rustc_mir_transform[b373b9de80ff07e8]::coroutine::by_move_body::ByMoveBody as rustc_middle[84b64d630b2bee13]::mir::MirPass>::run_pass
19: 0x7fffd322fa9c - <rustc_mir_transform[b373b9de80ff07e8]::simplify::SimplifyCfg as rustc_middle[84b64d630b2bee13]::mir::MirPass>::run_pass
20: 0x7fffd32c0c9d - rustc_mir_transform[b373b9de80ff07e8]::mir_built
21: 0x7fffd392193a - rustc_query_impl[33a1b4098950561d]::plumbing::query_key_hash_verify_all
22: 0x7fffd3875c1a - rustc_traits[a53074f1b4e9ea87]::type_op::type_op_prove_predicate
23: 0x7fffd2b22cfe - rustc_query_impl[33a1b4098950561d]::query_system
24: 0x7fffd29ca496 - rustc_ty_utils[c3d756d018202afc]::ty::adt_sized_constraint
25: 0x7fffd35d220a - <rustc_mir_build[4c126c57b954b35a]::check_unsafety::UnsafetyVisitor as rustc_middle[84b64d630b2bee13]::thir::visit::Visitor>::visit_expr
26: 0x7fffd29ca58e - rustc_ty_utils[c3d756d018202afc]::ty::adt_sized_constraint
27: 0x7fffd35d220a - <rustc_mir_build[4c126c57b954b35a]::check_unsafety::UnsafetyVisitor as rustc_middle[84b64d630b2bee13]::thir::visit::Visitor>::visit_expr
28: 0x7fffd35d1563 - <rustc_mir_build[4c126c57b954b35a]::check_unsafety::UnsafetyVisitor as rustc_middle[84b64d630b2bee13]::thir::visit::Visitor>::visit_block
29: 0x7fffd35d329d - <rustc_mir_build[4c126c57b954b35a]::check_unsafety::UnsafetyVisitor as rustc_middle[84b64d630b2bee13]::thir::visit::Visitor>::visit_expr
30: 0x7fffd35d220a - <rustc_mir_build[4c126c57b954b35a]::check_unsafety::UnsafetyVisitor as rustc_middle[84b64d630b2bee13]::thir::visit::Visitor>::visit_expr
31: 0x7fffd35d3f90 - rustc_mir_build[4c126c57b954b35a]::check_unsafety::check_unsafety
32: 0x7fffd39205ca - rustc_query_impl[33a1b4098950561d]::plumbing::query_key_hash_verify_all
33: 0x7fffd386aa5a - rustc_traits[a53074f1b4e9ea87]::type_op::type_op_prove_predicate
34: 0x7fffd39292ab - rustc_query_impl[33a1b4098950561d]::plumbing::query_key_hash_verify_all
35: 0x7fffd2ef45a4 - <rustc_interface[f65115e9a3f8b78a]::passes::LintStoreExpandImpl as rustc_expand[90c53b689c18a18c]::base::LintStoreExpand>::pre_expansion_lint
36: 0x7fffd2b1a86a - <dyn std[edc18776cd067f9d]::io::Write as nu_ansi_term[730eb3389a53a735]::write::AnyWrite>::write_str
37: 0x7fffd2a3a6c9 - rustc_traits[a53074f1b4e9ea87]::type_op::type_op_normalize_clause
38: 0x7fffd2b1fe13 - rustc_query_impl[33a1b4098950561d]::query_system
39: 0x7fffcfef2fd9 - __ImageBase
40: 0x7fffcfef0337 - __ImageBase
41: 0x7fffcfef8a89 - __ImageBase
42: 0x7ff8165678ed - alloc::boxed::impl$48::call_once
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\alloc\src\boxed.rs:2018
43: 0x7ff8165678ed - alloc::boxed::impl$48::call_once
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\alloc\src\boxed.rs:2018
44: 0x7ff8165678ed - std::sys::pal::windows::thread::impl$0::new::thread_start
at /rustc/ab5bda1aa70f707014e2e691e43bc37a8819252a/library\std\src\sys\pal\windows\thread.rs:53
45: 0x7ff85a297344 - BaseThreadInitThunk
46: 0x7ff85b4c26b1 - RtlUserThreadStart
error: the compiler unexpectedly panicked. this is a bug.
note: it seems that this compiler `1.79.0-nightly (ab5bda1aa 2024-04-08)` is outdated, a newer nightly should have been released in the meantime
|
= note: please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists
= note: if the problem still persists, 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 attach the file at `...` 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_built] building MIR for `test::{closure#0}::{closure#0}`
#1 [check_unsafety] unsafety-checking `test`
#2 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `testing` (bin "testing")```
ICE txt file:
[rustc-ice-2024-04-09T21_28_12-2316.txt](https://github.com/rust-lang/rust/files/14924081/rustc-ice-2024-04-09T21_28_12-2316.txt)