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

Regression/ICE: moving both a Copy type and a !Copy type into async move || { ... } (async_closure) #124487

Open
finnbear opened this issue Apr 28, 2024 · 1 comment
Assignees
Labels
C-bug Category: This is a bug. F-async_closure `#![feature(async_closure)]` I-prioritize Issue: Indicates that prioritization has been requested for this issue. requires-nightly This issue requires a nightly compiler in some way.

Comments

@finnbear
Copy link
Contributor

finnbear commented Apr 28, 2024

Code

I tried this code (minimized):

#![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>

Related: #120361
Mentioning @compiler-errors 😉

error -> ICE

********************************************************************************
Regression in 1921968cc5403892739b43bdefe793a130badd15
********************************************************************************

Best guess: #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 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::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::<alloc[1dedc0b6462c0e58]::boxed::Box<rustc_driver_impl[a06908b56a08a5f3]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f5b0bac0e56 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::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::<rustc_type_ir[f35b0a68110f4e13]::ClosureKind, rustc_type_ir[f35b0a68110f4e13]::ClosureKind>
  20:     0x7f5b0e383740 - <rustc_mir_transform[2378a63253b3ac0c]::coroutine::by_move_body::ByMoveBody as rustc_middle[fb5dda08dce04472]::mir::MirPass>::run_pass
  21:     0x7f5b0ff3394d - rustc_mir_transform[2378a63253b3ac0c]::pass_manager::run_passes_inner
  22:     0x7f5b102521a8 - rustc_query_impl[ffc1dc643be498fd]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ffc1dc643be498fd]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fb5dda08dce04472]::query::erase::Erased<[u8; 8usize]>>
  23:     0x7f5b10348771 - rustc_query_system[6eb3337d20c14267]::query::plumbing::try_execute_query::<rustc_query_impl[ffc1dc643be498fd]::DynamicConfig<rustc_query_system[6eb3337d20c14267]::query::caches::VecCache<rustc_span[413b5bd4996aee21]::def_id::LocalDefId, rustc_middle[fb5dda08dce04472]::query::erase::Erased<[u8; 8usize]>>, 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 - <rustc_mir_build[a31e700f633e9780]::check_unsafety::UnsafetyVisitor>::visit_inner_body
  26:     0x7f5b0d506cd4 - <rustc_mir_build[a31e700f633e9780]::check_unsafety::UnsafetyVisitor as rustc_middle[fb5dda08dce04472]::thir::visit::Visitor>::visit_expr
  27:     0x7f5b103341c1 - <rustc_mir_build[a31e700f633e9780]::check_unsafety::UnsafetyVisitor>::visit_inner_body
  28:     0x7f5b0d506cd4 - <rustc_mir_build[a31e700f633e9780]::check_unsafety::UnsafetyVisitor as rustc_middle[fb5dda08dce04472]::thir::visit::Visitor>::visit_expr
  29:     0x7f5b1077d119 - <rustc_mir_build[a31e700f633e9780]::check_unsafety::UnsafetyVisitor as rustc_middle[fb5dda08dce04472]::thir::visit::Visitor>::visit_block
  30:     0x7f5b0d507fd0 - <rustc_mir_build[a31e700f633e9780]::check_unsafety::UnsafetyVisitor as rustc_middle[fb5dda08dce04472]::thir::visit::Visitor>::visit_expr
  31:     0x7f5b0d506cd4 - <rustc_mir_build[a31e700f633e9780]::check_unsafety::UnsafetyVisitor as rustc_middle[fb5dda08dce04472]::thir::visit::Visitor>::visit_expr
  32:     0x7f5b10331324 - rustc_mir_build[a31e700f633e9780]::check_unsafety::check_unsafety
  33:     0x7f5b10330dd1 - rustc_query_impl[ffc1dc643be498fd]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ffc1dc643be498fd]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fb5dda08dce04472]::query::erase::Erased<[u8; 0usize]>>
  34:     0x7f5b1032fe4d - rustc_query_system[6eb3337d20c14267]::query::plumbing::try_execute_query::<rustc_query_impl[ffc1dc643be498fd]::DynamicConfig<rustc_query_system[6eb3337d20c14267]::query::caches::VecCache<rustc_span[413b5bd4996aee21]::def_id::LocalDefId, rustc_middle[fb5dda08dce04472]::query::erase::Erased<[u8; 0usize]>>, 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::<rustc_query_impl[ffc1dc643be498fd]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fb5dda08dce04472]::query::erase::Erased<[u8; 1usize]>>
  38:     0x7f5b10d2a9e5 - rustc_query_system[6eb3337d20c14267]::query::plumbing::try_execute_query::<rustc_query_impl[ffc1dc643be498fd]::DynamicConfig<rustc_query_system[6eb3337d20c14267]::query::caches::SingleCache<rustc_middle[fb5dda08dce04472]::query::erase::Erased<[u8; 1usize]>>, 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::<core[3cc7221ca1340ad0]::result::Result<(), rustc_span[413b5bd4996aee21]::ErrorGuaranteed>, rustc_driver_impl[a06908b56a08a5f3]::run_compiler::{closure#0}>::{closure#1}
  41:     0x7f5b10b77327 - std[f6dbfb092428beee]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[7ce95aec19cf85e]::util::run_in_thread_with_globals<rustc_interface[7ce95aec19cf85e]::util::run_in_thread_pool_with_globals<rustc_interface[7ce95aec19cf85e]::interface::run_compiler<core[3cc7221ca1340ad0]::result::Result<(), rustc_span[413b5bd4996aee21]::ErrorGuaranteed>, 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 - <<std[f6dbfb092428beee]::thread::Builder>::spawn_unchecked_<rustc_interface[7ce95aec19cf85e]::util::run_in_thread_with_globals<rustc_interface[7ce95aec19cf85e]::util::run_in_thread_pool_with_globals<rustc_interface[7ce95aec19cf85e]::interface::run_compiler<core[3cc7221ca1340ad0]::result::Result<(), rustc_span[413b5bd4996aee21]::ErrorGuaranteed>, 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 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8f96bdbdef28286c
                               at /rustc/aed2187d53b8789e3a37f50ae36f894a2a679077/library/alloc/src/boxed.rs:2022:9
  44:     0x7f5b0bacac8b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::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 - <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-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 { ... }

@finnbear finnbear added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Apr 28, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 28, 2024
@compiler-errors compiler-errors self-assigned this Apr 28, 2024
@compiler-errors
Copy link
Member

Nightly-only features aren't typically regression triaged. I'll look into it soon.

@compiler-errors compiler-errors added F-async_closure `#![feature(async_closure)]` requires-nightly This issue requires a nightly compiler in some way. and removed regression-untriaged Untriaged performance or correctness regression. labels Apr 28, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 10, 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-prioritize Issue: Indicates that prioritization has been requested for this issue. requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

No branches or pull requests

4 participants