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

ICE: leftover child captures? #123901

Closed
matthiaskrgr opened this issue Apr 13, 2024 · 8 comments
Closed

ICE: leftover child captures? #123901

matthiaskrgr opened this issue Apr 13, 2024 · 8 comments
Assignees
Labels
A-async-await Area: Async & Await AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

pub fn test(test: &u64, temp: &u64) {
    async |check, a, b| {
        temp.abs_diff(12);
    };
}

original:

#![feature(async_closure, async_fn_traits)]

fn main() {}

pub fn test(test: &u64, temp: &u64) {
    let test = test.clone();
    async |check, a, b| {
        temp.abs_diff(12);
        test.clone();
    };
}

Version information

rustc 1.79.0-nightly (3a0db6c15 2024-04-13)
binary: rustc
commit-hash: 3a0db6c15251a56a02f4d0171d3e9586f86abd44
commit-date: 2024-04-13
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.3

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --edition=2021

Program output

error[E0658]: async closures are unstable
 --> /tmp/icemaker_global_tempdir.NfjNL9cyB5N3/rustc_testrunner_tmpdir_reporting.W54CO64GoeWB/mvce.rs:2:5
  |
2 |     async |check, a, b| {
  |     ^^^^^
  |
  = note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
  = help: add `#![feature(async_closure)]` to the crate attributes to enable
  = note: this compiler was built on 2024-04-13; consider upgrading it if it is out of date
  = help: to use an async block, remove the `||`: `async {`

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.NfjNL9cyB5N3/rustc_testrunner_tmpdir_reporting.W54CO64GoeWB/mvce.rs:5:2
  |
5 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.NfjNL9cyB5N3/rustc_testrunner_tmpdir_reporting.W54CO64GoeWB/mvce.rs`

thread 'rustc' panicked at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/compiler/rustc_middle/src/ty/closure.rs:465:9:
assertion `left == right` failed: leftover child captures?
  left: Some((0, CapturedPlace { var_ident: temp#0, place: Place { base_ty: &ReLateParam(DefId(0:3 ~ mvce[c50b]::test), BrNamed(DefId(0:7 ~ mvce[c50b]::test::'_#1), '_)) u64, base: Upvar(UpvarId(HirId(DefId(0:3 ~ mvce[c50b]::test).4);`temp`;DefId(0:5 ~ mvce[c50b]::test::{closure#0}::{closure#0}))), projections: [Projection { ty: u64, kind: Deref }] }, info: CaptureInfo { capture_kind_expr_id: Some(HirId(DefId(0:3 ~ mvce[c50b]::test).34)), path_expr_id: Some(HirId(DefId(0:3 ~ mvce[c50b]::test).34)), capture_kind: ByRef(ImmBorrow) }, mutability: Not, region: Some('?0) }))
 right: None
stack backtrace:
   0:     0x723435201c05 - std::backtrace_rs::backtrace::libunwind::trace::he67d23302a415162
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x723435201c05 - std::backtrace_rs::backtrace::trace_unsynchronized::h39e708adc62db50c
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x723435201c05 - std::sys_common::backtrace::_print_fmt::h2cd8591d0bde0854
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x723435201c05 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hefdd442146db74bf
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x723435250f3b - core::fmt::rt::Argument::fmt::h7a4c8d2d1224ab4a
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/core/src/fmt/rt.rs:142:9
   5:     0x723435250f3b - core::fmt::write::hf0b695e14076a26d
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/core/src/fmt/mod.rs:1153:17
   6:     0x7234351f680f - std::io::Write::write_fmt::h71fcd2625aa9c332
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/std/src/io/mod.rs:1832:15
   7:     0x7234352019de - std::sys_common::backtrace::_print::hdeb11c462cc75e10
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7234352019de - std::sys_common::backtrace::print::h191e80b695c7e36e
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x723435204359 - std::panicking::default_hook::{{closure}}::h8d77c83f4f715071
  10:     0x72343520409d - std::panicking::default_hook::h5f0148e464f5b814
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/std/src/panicking.rs:291:9
  11:     0x723431a7664c - std[885a30522c002bbc]::panicking::update_hook::<alloc[e68b43253f4aa917]::boxed::Box<rustc_driver_impl[90e9a40ab560bf54]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x723435204a5c - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h67d1278a639bc027
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/alloc/src/boxed.rs:2032:9
  13:     0x723435204a5c - std::panicking::rust_panic_with_hook::h7b2f32c16086f787
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/std/src/panicking.rs:792:13
  14:     0x723435204806 - std::panicking::begin_panic_handler::{{closure}}::hc9d8693313be9056
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/std/src/panicking.rs:657:13
  15:     0x7234352020c9 - std::sys_common::backtrace::__rust_end_short_backtrace::h6aae8c655dbc3423
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x723435204537 - rust_begin_unwind
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/std/src/panicking.rs:645:5
  17:     0x72343524d3d6 - core::panicking::panic_fmt::hf0b729b119d27b91
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/core/src/panicking.rs:72:14
  18:     0x72343524d99f - core::panicking::assert_failed_inner::h260765b39fc64692
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/core/src/panicking.rs:397:23
  19:     0x723431bf60db - core[75462145d81de164]::panicking::assert_failed::<core[75462145d81de164]::option::Option<(usize, &rustc_middle[634cd321d1104505]::ty::closure::CapturedPlace)>, core[75462145d81de164]::option::Option<(usize, &rustc_middle[634cd321d1104505]::ty::closure::CapturedPlace)>>
  20:     0x723431c240d1 - <core[75462145d81de164]::iter::sources::from_coroutine::FromCoroutine<rustc_middle[634cd321d1104505]::ty::closure::analyze_coroutine_closure_captures<rustc_middle[634cd321d1104505]::ty::Ty, core[75462145d81de164]::iter::adapters::flatten::Flatten<core[75462145d81de164]::option::IntoIter<core[75462145d81de164]::iter::adapters::flatten::FlatMap<indexmap[9236e8704059c4ca]::map::iter::Values<rustc_hir[b517bd588d68daf0]::hir_id::HirId, alloc[e68b43253f4aa917]::vec::Vec<rustc_middle[634cd321d1104505]::ty::closure::CapturedPlace>>, core[75462145d81de164]::slice::iter::Iter<rustc_middle[634cd321d1104505]::ty::closure::CapturedPlace>, <rustc_middle[634cd321d1104505]::ty::typeck_results::TypeckResults>::closure_min_captures_flattened::{closure#0}::{closure#0}>>>, core[75462145d81de164]::iter::adapters::skip::Skip<core[75462145d81de164]::iter::adapters::flatten::Flatten<core[75462145d81de164]::option::IntoIter<core[75462145d81de164]::iter::adapters::flatten::FlatMap<indexmap[9236e8704059c4ca]::map::iter::Values<rustc_hir[b517bd588d68daf0]::hir_id::HirId, alloc[e68b43253f4aa917]::vec::Vec<rustc_middle[634cd321d1104505]::ty::closure::CapturedPlace>>, core[75462145d81de164]::slice::iter::Iter<rustc_middle[634cd321d1104505]::ty::closure::CapturedPlace>, <rustc_middle[634cd321d1104505]::ty::typeck_results::TypeckResults>::closure_min_captures_flattened::{closure#0}::{closure#0}>>>>, <rustc_hir_typeck[6df0519c0ec70ff8]::fn_ctxt::FnCtxt>::analyze_closure::{closure#0}>::{closure#0}> as core[75462145d81de164]::iter::traits::iterator::Iterator>::next
  21:     0x7234337cf624 - <rustc_hir_typeck[6df0519c0ec70ff8]::fn_ctxt::FnCtxt>::analyze_closure
  22:     0x72342ff0c0bb - <rustc_hir_typeck[6df0519c0ec70ff8]::upvar::InferBorrowKindVisitor as rustc_hir[b517bd588d68daf0]::intravisit::Visitor>::visit_expr
  23:     0x723432fe0ec4 - <rustc_hir_typeck[6df0519c0ec70ff8]::upvar::InferBorrowKindVisitor as rustc_hir[b517bd588d68daf0]::intravisit::Visitor>::visit_block
  24:     0x723432fe319c - rustc_hir_typeck[6df0519c0ec70ff8]::typeck
  25:     0x723432fe2889 - rustc_query_impl[20b47d821f71e0c0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[20b47d821f71e0c0]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[634cd321d1104505]::query::erase::Erased<[u8; 8usize]>>
  26:     0x723432fceef1 - rustc_query_system[b7ba67b5501de1f1]::query::plumbing::try_execute_query::<rustc_query_impl[20b47d821f71e0c0]::DynamicConfig<rustc_query_system[b7ba67b5501de1f1]::query::caches::VecCache<rustc_span[1f0db57e54aaa535]::def_id::LocalDefId, rustc_middle[634cd321d1104505]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[20b47d821f71e0c0]::plumbing::QueryCtxt, false>
  27:     0x723432fcd80c - rustc_query_impl[20b47d821f71e0c0]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  28:     0x723432fcd3d4 - <rustc_middle[634cd321d1104505]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[813d3a9100b7eb57]::check_crate::{closure#4}>::{closure#0}
  29:     0x723432fcc0aa - rustc_hir_analysis[813d3a9100b7eb57]::check_crate
  30:     0x72343372b47a - rustc_interface[584c726233b098e3]::passes::analysis
  31:     0x72343372afd5 - rustc_query_impl[20b47d821f71e0c0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[20b47d821f71e0c0]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[634cd321d1104505]::query::erase::Erased<[u8; 1usize]>>
  32:     0x723433c30f65 - rustc_query_system[b7ba67b5501de1f1]::query::plumbing::try_execute_query::<rustc_query_impl[20b47d821f71e0c0]::DynamicConfig<rustc_query_system[b7ba67b5501de1f1]::query::caches::SingleCache<rustc_middle[634cd321d1104505]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[20b47d821f71e0c0]::plumbing::QueryCtxt, false>
  33:     0x723433c30cc9 - rustc_query_impl[20b47d821f71e0c0]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  34:     0x723433ad5093 - rustc_interface[584c726233b098e3]::interface::run_compiler::<core[75462145d81de164]::result::Result<(), rustc_span[1f0db57e54aaa535]::ErrorGuaranteed>, rustc_driver_impl[90e9a40ab560bf54]::run_compiler::{closure#0}>::{closure#0}
  35:     0x723433ba921d - std[885a30522c002bbc]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[584c726233b098e3]::util::run_in_thread_with_globals<rustc_interface[584c726233b098e3]::util::run_in_thread_pool_with_globals<rustc_interface[584c726233b098e3]::interface::run_compiler<core[75462145d81de164]::result::Result<(), rustc_span[1f0db57e54aaa535]::ErrorGuaranteed>, rustc_driver_impl[90e9a40ab560bf54]::run_compiler::{closure#0}>::{closure#0}, core[75462145d81de164]::result::Result<(), rustc_span[1f0db57e54aaa535]::ErrorGuaranteed>>::{closure#0}, core[75462145d81de164]::result::Result<(), rustc_span[1f0db57e54aaa535]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[75462145d81de164]::result::Result<(), rustc_span[1f0db57e54aaa535]::ErrorGuaranteed>>
  36:     0x723433ba902a - <<std[885a30522c002bbc]::thread::Builder>::spawn_unchecked_<rustc_interface[584c726233b098e3]::util::run_in_thread_with_globals<rustc_interface[584c726233b098e3]::util::run_in_thread_pool_with_globals<rustc_interface[584c726233b098e3]::interface::run_compiler<core[75462145d81de164]::result::Result<(), rustc_span[1f0db57e54aaa535]::ErrorGuaranteed>, rustc_driver_impl[90e9a40ab560bf54]::run_compiler::{closure#0}>::{closure#0}, core[75462145d81de164]::result::Result<(), rustc_span[1f0db57e54aaa535]::ErrorGuaranteed>>::{closure#0}, core[75462145d81de164]::result::Result<(), rustc_span[1f0db57e54aaa535]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[75462145d81de164]::result::Result<(), rustc_span[1f0db57e54aaa535]::ErrorGuaranteed>>::{closure#2} as core[75462145d81de164]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  37:     0x72343520e95b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7e43c058cec37c3f
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/alloc/src/boxed.rs:2018:9
  38:     0x72343520e95b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h318f41c47f558002
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/alloc/src/boxed.rs:2018:9
  39:     0x72343520e95b - std::sys::pal::unix::thread::Thread::new::thread_start::hb16ab7f697c5a952
                               at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/std/src/sys/pal/unix/thread.rs:108:17
  40:     0x723434fac55a - <unknown>
  41:     0x723435029a3c - <unknown>
  42:                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: rustc 1.79.0-nightly (3a0db6c15 2024-04-13) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dump-mir-dir=dir

query stack during panic:
#0 [typeck] type-checking `test`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0601, E0658.
For more information about an error, try `rustc --explain E0601`.

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Apr 13, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 13, 2024
@matthiaskrgr matthiaskrgr changed the title ICE: `leftover child captures? ICE: leftover child captures? Apr 13, 2024
@matthiaskrgr
Copy link
Member Author

pub fn test(temp: &u64) {
    async |_| {
        temp;
    };
}

pub fn main() {}

@compiler-errors compiler-errors self-assigned this Apr 13, 2024
@compiler-errors
Copy link
Member

Not fixed by #123834? Can't check -- not at my rust workstation.

@matthiaskrgr
Copy link
Member Author

nope, still crashes with latest git master toolchain.

@compiler-errors
Copy link
Member

kk

@matthiaskrgr
Copy link
Member Author

BUT I only found 3 of those in one million files, instead of several thousands, so definitely an improvement 🙃

@jieyouxu jieyouxu added A-async-await Area: Async & Await S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 15, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 18, 2024
@cushionbadak
Copy link

searched nightlies: from nightly-2024-01-01 to nightly-2024-04-12
regressed nightly: nightly-2024-04-12
searched commit range: aa067fb...a07f3eb
regressed commit: df7daa8

bisected with cargo-bisect-rustc v0.6.8

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start 2024-01-01 --end 2024-04-12 --preserve --regress ice

@traviscross
Copy link
Contributor

@rustbot labels +AsyncAwait-Triaged

We discussed this in async triage today. Looks like work is proceeding here, so we can mark this as triaged.

@matthiaskrgr
Copy link
Member Author

Fixed by #124902

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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

Successfully merging a pull request may close this issue.

6 participants