#![feature(async_closure)]
fn foo() {
// no ICE if removed or made !Copy
let bar = 0u8;
// no ICE if removed or made Copy
let baz = "".to_owned();
async move || {
let _ = (bar, baz);
};
}
fn main() {}
I expected to see this happen: Compiles
Instead, this happened (nightly-2024-02-09):
error[E0597]: `bar` does not live long enough
--> src/main.rs:7:18
|
6 | async move || {
| ___________________-
7 | | let _ = (bar, baz);
| | ^^^ borrowed value does not live long enough
8 | | };
| | -- borrow later used here
| | |
| |_____`bar` dropped here while still borrowed
| value captured here by coroutine
Instead, this happened (latest nightly): ICE
Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at compiler/rustc_mir_transform/src/coroutine/by_move_body.rs:140:21:
assertion `left != right` failed: `FnOnce` coroutine-closures return coroutines that capture from their body; it will always result in a borrowck error!
left: FnOnce
right: FnOnce
Versions
working -> error
searched nightlies: from nightly-2023-04-25 to nightly-2024-04-20
regressed nightly: nightly-2024-02-07
searched commit range: https://github.com/rust-lang/rust/compare/f067fd6084d750f3797f54b71771c5dbc149726f...256b6fb19a2c018eaad4806d2369d1f6a71fc6ec
regressed commit: https://github.com/rust-lang/rust/commit/4a2fe4491ea616983a0cf0cbbd145a39768f4e7a
<details>
<summary>bisected with <a href='https://github.com/rust-lang/cargo-bisect-rustc'>cargo-bisect-rustc</a> v0.6.6</summary>
********************************************************************************
Regression in 1921968cc5403892739b43bdefe793a130badd15
********************************************************************************
Code
I tried this code (minimized):
I expected to see this happen: Compiles
Instead, this happened (
nightly-2024-02-09
):Instead, this happened (latest nightly): ICE
Versions
working -> error
Related: https://github.com/rust-lang/rust/pull/120361 Mentioning @compiler-errors :wink:
error -> ICE
Best guess: https://github.com/rust-lang/rust/pull/123350
Backtrace
``` Compiling playground v0.0.1 (/playground) thread 'rustc' panicked at compiler/rustc_mir_transform/src/coroutine/by_move_body.rs:140:21: assertion `left != right` failed: `FnOnce` coroutine-closures return coroutines that capture from their body; it will always result in a borrowck error! left: FnOnce right: FnOnce stack backtrace: 0: 0x7f5b0babe015 - std::backtrace_rs::backtrace::libunwind::trace::h202d45d8fd20a824 at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5 1: 0x7f5b0babe015 - std::backtrace_rs::backtrace::trace_unsynchronized::h1daee13ebb59eeb4 at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f5b0babe015 - std::sys_common::backtrace::_print_fmt::hf1c1d6c712400d1b at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/std/src/sys_common/backtrace.rs:68:5 3: 0x7f5b0babe015 -::fmt::ha6cb3dac0d776969
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/std/src/sys_common/backtrace.rs:44:22
4: 0x7f5b0bb0d27b - core::fmt::rt::Argument::fmt::hb86c5e5f8ba90810
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/core/src/fmt/rt.rs:165:63
5: 0x7f5b0bb0d27b - core::fmt::write::h5b057186bbc5fec2
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/core/src/fmt/mod.rs:1157:21
6: 0x7f5b0bab2bbf - std::io::Write::write_fmt::h62aa7b9115cec986
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/std/src/io/mod.rs:1832:15
7: 0x7f5b0babddee - std::sys_common::backtrace::_print::hdfcedaa64cb5957c
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/std/src/sys_common/backtrace.rs:47:5
8: 0x7f5b0babddee - std::sys_common::backtrace::print::h128dd53d70614027
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/std/src/sys_common/backtrace.rs:34:9
9: 0x7f5b0bac0759 - std::panicking::default_hook::{{closure}}::h25cd5b2272122564
10: 0x7f5b0bac049d - std::panicking::default_hook::h3f62a662b49f346a
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/std/src/panicking.rs:298:9
11: 0x7f5b0eb62d0c - std[f6dbfb092428beee]::panicking::update_hook::>::{closure#0}
12: 0x7f5b0bac0e56 - as core::ops::function::Fn>::call::h195b48b24ae880e2
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/alloc/src/boxed.rs:2036:9
13: 0x7f5b0bac0e56 - std::panicking::rust_panic_with_hook::h906fa2f149cd991b
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/std/src/panicking.rs:799:13
14: 0x7f5b0bac0c04 - std::panicking::begin_panic_handler::{{closure}}::hf5f40df14bc3ecc3
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/std/src/panicking.rs:664:13
15: 0x7f5b0babe4d9 - std::sys_common::backtrace::__rust_end_short_backtrace::h6caf7624fbbe1a8f
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/std/src/sys_common/backtrace.rs:171:18
16: 0x7f5b0bac0937 - rust_begin_unwind
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/std/src/panicking.rs:652:5
17: 0x7f5b0bb09743 - core::panicking::panic_fmt::h24ccdca200c3cead
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/core/src/panicking.rs:72:14
18: 0x7f5b0bb09d0f - core::panicking::assert_failed_inner::h154a63e2b6258de7
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/core/src/panicking.rs:404:23
19: 0x7f5b0f161938 - core[3cc7221ca1340ad0]::panicking::assert_failed::
20: 0x7f5b0e383740 - ::run_pass
21: 0x7f5b0ff3394d - rustc_mir_transform[2378a63253b3ac0c]::pass_manager::run_passes_inner
22: 0x7f5b102521a8 - rustc_query_impl[ffc1dc643be498fd]::plumbing::__rust_begin_short_backtrace::>
23: 0x7f5b10348771 - rustc_query_system[6eb3337d20c14267]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[ffc1dc643be498fd]::plumbing::QueryCtxt, false>
24: 0x7f5b1034828c - rustc_query_impl[ffc1dc643be498fd]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
25: 0x7f5b103340b0 - ::visit_inner_body
26: 0x7f5b0d506cd4 - ::visit_expr
27: 0x7f5b103341c1 - ::visit_inner_body
28: 0x7f5b0d506cd4 - ::visit_expr
29: 0x7f5b1077d119 - ::visit_block
30: 0x7f5b0d507fd0 - ::visit_expr
31: 0x7f5b0d506cd4 - ::visit_expr
32: 0x7f5b10331324 - rustc_mir_build[a31e700f633e9780]::check_unsafety::check_unsafety
33: 0x7f5b10330dd1 - rustc_query_impl[ffc1dc643be498fd]::plumbing::__rust_begin_short_backtrace::>
34: 0x7f5b1032fe4d - rustc_query_system[6eb3337d20c14267]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[ffc1dc643be498fd]::plumbing::QueryCtxt, false>
35: 0x7f5b1032faff - rustc_query_impl[ffc1dc643be498fd]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
36: 0x7f5b103282e5 - rustc_interface[7ce95aec19cf85e]::passes::analysis
37: 0x7f5b103273d5 - rustc_query_impl[ffc1dc643be498fd]::plumbing::__rust_begin_short_backtrace::>
38: 0x7f5b10d2a9e5 - rustc_query_system[6eb3337d20c14267]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[ffc1dc643be498fd]::plumbing::QueryCtxt, false>
39: 0x7f5b10d2a749 - rustc_query_impl[ffc1dc643be498fd]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
40: 0x7f5b10b8a98e - rustc_interface[7ce95aec19cf85e]::interface::run_compiler::, rustc_driver_impl[a06908b56a08a5f3]::run_compiler::{closure#0}>::{closure#1}
41: 0x7f5b10b77327 - std[f6dbfb092428beee]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[a06908b56a08a5f3]::run_compiler::{closure#0}>::{closure#1}, core[3cc7221ca1340ad0]::result::Result<(), rustc_span[413b5bd4996aee21]::ErrorGuaranteed>>::{closure#0}, core[3cc7221ca1340ad0]::result::Result<(), rustc_span[413b5bd4996aee21]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3cc7221ca1340ad0]::result::Result<(), rustc_span[413b5bd4996aee21]::ErrorGuaranteed>>
42: 0x7f5b10b770ea - <::spawn_unchecked_, rustc_driver_impl[a06908b56a08a5f3]::run_compiler::{closure#0}>::{closure#1}, core[3cc7221ca1340ad0]::result::Result<(), rustc_span[413b5bd4996aee21]::ErrorGuaranteed>>::{closure#0}, core[3cc7221ca1340ad0]::result::Result<(), rustc_span[413b5bd4996aee21]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3cc7221ca1340ad0]::result::Result<(), rustc_span[413b5bd4996aee21]::ErrorGuaranteed>>::{closure#2} as core[3cc7221ca1340ad0]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
43: 0x7f5b0bacac8b - as core::ops::function::FnOnce>::call_once::h8f96bdbdef28286c
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/alloc/src/boxed.rs:2022:9
44: 0x7f5b0bacac8b - as core::ops::function::FnOnce>::call_once::hdc6d9d278290e1ae
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/alloc/src/boxed.rs:2022:9
45: 0x7f5b0bacac8b - std::sys::pal::unix::thread::Thread::new::thread_start::hd8b6cbeea7b365c6
at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/std/src/sys/pal/unix/thread.rs:108:17
46: 0x7f5b0b9d8609 - start_thread
47: 0x7f5b0b8fb353 - clone
48: 0x0 -
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-04-28T18_30_30-119.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_built] building MIR for `foo::{closure#0}::{closure#0}`
#1 [check_unsafety] unsafety-checking `foo`
#2 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `playground` (bin "playground")
```
@rustbot modify labels: +regression-from-nightly-to-nightly -regression-untriaged
Thanks for investigating!
Workaround
async move || { ... }
->move || async move { ... }