rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.91k stars 12.52k forks source link

ICE: `leftover child captures?` #123901

Closed matthiaskrgr closed 4 months ago

matthiaskrgr commented 5 months ago

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 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 - ::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::>::{closure#0} 12: 0x723435204a5c - as core::ops::function::Fn>::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)>> 20: 0x723431c240d1 - >, core[75462145d81de164]::slice::iter::Iter, ::closure_min_captures_flattened::{closure#0}::{closure#0}>>>, core[75462145d81de164]::iter::adapters::skip::Skip>, core[75462145d81de164]::slice::iter::Iter, ::closure_min_captures_flattened::{closure#0}::{closure#0}>>>>, ::analyze_closure::{closure#0}>::{closure#0}> as core[75462145d81de164]::iter::traits::iterator::Iterator>::next 21: 0x7234337cf624 - ::analyze_closure 22: 0x72342ff0c0bb - ::visit_expr 23: 0x723432fe0ec4 - ::visit_block 24: 0x723432fe319c - rustc_hir_typeck[6df0519c0ec70ff8]::typeck 25: 0x723432fe2889 - rustc_query_impl[20b47d821f71e0c0]::plumbing::__rust_begin_short_backtrace::> 26: 0x723432fceef1 - rustc_query_system[b7ba67b5501de1f1]::query::plumbing::try_execute_query::>, 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 - ::par_body_owners::::{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::> 32: 0x723433c30f65 - rustc_query_system[b7ba67b5501de1f1]::query::plumbing::try_execute_query::>, 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::, rustc_driver_impl[90e9a40ab560bf54]::run_compiler::{closure#0}>::{closure#0} 35: 0x723433ba921d - std[885a30522c002bbc]::sys_common::backtrace::__rust_begin_short_backtrace::, 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 - <::spawn_unchecked_, 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 - as core::ops::function::FnOnce>::call_once::h7e43c058cec37c3f at /rustc/3a0db6c15251a56a02f4d0171d3e9586f86abd44/library/alloc/src/boxed.rs:2018:9 38: 0x72343520e95b - as core::ops::function::FnOnce>::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 - 41: 0x723435029a3c - 42: 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: 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 commented 5 months ago
pub fn test(temp: &u64) {
    async |_| {
        temp;
    };
}

pub fn main() {}
compiler-errors commented 5 months ago

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

matthiaskrgr commented 5 months ago

nope, still crashes with latest git master toolchain.

compiler-errors commented 5 months ago

kk

matthiaskrgr commented 5 months ago

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

cushionbadak commented 4 months ago

searched nightlies: from nightly-2024-01-01 to nightly-2024-04-12 regressed nightly: nightly-2024-04-12 searched commit range: https://github.com/rust-lang/rust/compare/aa067fb984d36462548bb785da221bfaf38253f0...a07f3eb43acc5df851e15176c7081a900a30a4d7 regressed commit: https://github.com/rust-lang/rust/commit/df7daa815f4047a1cfe24ecfbc12cfd4f40fa928

bisected with cargo-bisect-rustc v0.6.8 Host triple: x86_64-unknown-linux-gnu Reproduce with: ```bash cargo bisect-rustc --start 2024-01-01 --end 2024-04-12 --preserve --regress ice ```
traviscross commented 4 months ago

@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 commented 4 months ago

Fixed by https://github.com/rust-lang/rust/pull/124902