Skip to content

ICE: async_fn_traits - error performing ParamEnvAnd when moving non-Copy value to async closure #121599

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
chrismooredev opened this issue Feb 25, 2024 · 1 comment · Fixed by #121617
Assignees
Labels
C-bug Category: This is a bug. F-async_fn_traits `#![feature(async_fn_traits)]` 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.

Comments

@chrismooredev
Copy link

chrismooredev commented Feb 25, 2024

Encountered an ICE when attempting to use the async_fn_traits feature. Seems to be related to moving non-copy values into it. Traditional usage would be a regular compiler error.

I believe this is the same error, just... not as pretty :)
error[E0507]: cannot move out of `value`, a captured variable in an `FnMut` closure

Code

#![feature(async_fn_traits)]

use std::future::Future;
use std::ops::AsyncFnMut;

struct Processor;

async fn foo() {
    let value = String::from("hello ice!"); // our owned non-`Copy` value
    
    // let value = &value; // shadow the value with a `Copy` reference to it
    
    // ICE without `value` shadow, compiles with shadow
    Processor.process_asyncfn(|| async move {
        println!("{:?}", value);
        ()
    });
    
    // compile error without shadow, compiles with shadow
    // Processor.process_fn_fut(|| async move {
    //     println!("{}", value);
    //     ()
    // });
}

impl Processor {
    async fn process_asyncfn<'f, F>(&'f mut self, mut f: F) -> ()
    where
        F: AsyncFnMut() -> (),
    { return f().await }
    
    async fn process_fn_fut<'f, F, Fut>(&'f mut self, mut f: F) -> ()
    where
        F: FnMut() -> Fut,
        Fut: Future<Output = ()>,
    { return f().await }
}

Meta

rustc --version --verbose: (tested with the Rust playground)

1.78.0-nightly (2024-02-24 381d69953bb7c3390cec)

Error output

error: internal compiler error: error performing ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: ProvePredicate { predicate: Binder { value: TraitPredicate(<{closure@src/lib.rs:14:31: 14:33} as std::ops::AsyncFnMut<()>>, polarity:Positive), bound_vars: [] } } }
  --> src/lib.rs:14:5
   |
14 | /     Processor.process_asyncfn(|| async move {
15 | |         println!("{:?}", owned);
16 | |         ()
17 | |     });
   | |______^
   |
Backtrace

note: delayed at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs:165:29
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxt>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_borrowck::type_check::TypeChecker>::fully_perform_op::<(), rustc_middle::ty::ParamEnvAnd<rustc_middle::traits::query::type_op::ProvePredicate>>
         4: <rustc_borrowck::type_check::TypeChecker>::normalize_and_prove_instantiated_predicates
         5: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_constant
         6: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_body
         7: rustc_borrowck::type_check::type_check
         8: rustc_borrowck::nll::compute_regions
         9: rustc_borrowck::do_mir_borrowck
        10: rustc_borrowck::mir_borrowck
        11: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        12: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        13: rustc_query_impl::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
        14: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
        15: <rustc_borrowck::type_check::TypeChecker>::prove_closure_bounds
        16: <rustc_borrowck::type_check::TypeChecker>::typeck_mir
        17: rustc_borrowck::type_check::type_check
        18: rustc_borrowck::nll::compute_regions
        19: rustc_borrowck::do_mir_borrowck
        20: rustc_borrowck::mir_borrowck
        21: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        22: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        23: rustc_query_impl::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
        24: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
        25: rustc_hir_analysis::collect::type_of::type_of_opaque
        26: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        27: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        28: rustc_query_impl::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace
        29: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
        30: rustc_hir_analysis::collect::type_of::type_of
        31: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        32: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        33: rustc_query_impl::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
        34: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
        35: rustc_hir_analysis::check::check::check_item_type
        36: rustc_hir_analysis::check::wfcheck::check_well_formed
        37: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        38: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_hir::hir_id::OwnerId, rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        39: rustc_query_impl::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
        40: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
        41: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        42: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalModDefId, rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        43: rustc_query_impl::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
        44: rustc_middle::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalModDefId, rustc_middle::query::erase::Erased<[u8; 1]>>, ()>
        45: rustc_hir_analysis::check_crate
        46: rustc_interface::passes::analysis
        47: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        48: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        49: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        50: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
        51: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        52: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        53: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/alloc/src/boxed.rs:2016:9
        54: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/alloc/src/boxed.rs:2016:9
        55: std::sys::pal::unix::thread::Thread::new::thread_start
                   at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/sys/pal/unix/thread.rs:108:17
        56: start_thread
        57: clone

@chrismooredev chrismooredev added C-bug Category: This is a bug. 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. labels Feb 25, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 25, 2024
@compiler-errors
Copy link
Member

Thanks for the issue report. I'll fix it tomorrow

@rustbot claim

@jieyouxu jieyouxu added F-async_fn_traits `#![feature(async_fn_traits)]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 26, 2024
@bors bors closed this as completed in 4f167b4 Feb 26, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 26, 2024
Rollup merge of rust-lang#121617 - compiler-errors:async-closure-kind-check, r=oli-obk

Actually use the right closure kind when checking async Fn goals

Dumb copy-paste mistake on my part from rust-lang#120712. Sorry!

r? oli-obk

Fixes rust-lang#121599
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. F-async_fn_traits `#![feature(async_fn_traits)]` 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants