ICE: async_fn_traits - error performing ParamEnvAnd when moving non-Copy value to async closure · Issue #121599 · rust-lang/rust (original) (raw)

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:🆕:thread_start
                   at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/sys/pal/unix/thread.rs:108:17
        56: start_thread
        57: clone