02ee8a8cee
Actually use the inferred `ClosureKind` from signature inference in coroutine-closures A follow-up to https://github.com/rust-lang/rust/pull/123349, which fixes another subtle bug: We were not taking into account the async closure kind we infer during closure signature inference. When I pass a closure directly to an arg like `fn(x: impl async FnOnce())`, that should have the side-effect of artificially restricting the kind of the async closure to `ClosureKind::FnOnce`. We weren't doing this -- that's a quick fix; however, it uncovers a second, more subtle bug with the way that `move`, async closures, and `FnOnce` interact. Specifically, when we have an async closure like: ``` let x = Struct; let c = infer_as_fnonce(async move || { println!("{x:?}"); } ``` The outer closure captures `x` by move, but the inner coroutine still immutably borrows `x` from the outer closure. Since we've forced the closure to by `async FnOnce()`, we can't actually *do* a self borrow, since the signature of `AsyncFnOnce::call_once` doesn't have a borrowed lifetime. This means that all `async move` closures that are constrained to `FnOnce` will fail borrowck. We can fix that by detecting this case specifically, and making the *inner* async closure `move` as well. This is always beneficial to closure analysis, since if we have an `async FnOnce()` that's `move`, there's no reason to ever borrow anything, so `move` isn't artificially restrictive. |
||
---|---|---|
.. | ||
coroutine | ||
coverage | ||
inline | ||
abort_unwinding_calls.rs | ||
add_call_guards.rs | ||
add_moves_for_packed_drops.rs | ||
add_retag.rs | ||
add_subtyping_projections.rs | ||
check_alignment.rs | ||
check_const_item_mutation.rs | ||
check_packed_ref.rs | ||
cleanup_post_borrowck.rs | ||
const_debuginfo.rs | ||
copy_prop.rs | ||
coroutine.rs | ||
cost_checker.rs | ||
cross_crate_inline.rs | ||
ctfe_limit.rs | ||
dataflow_const_prop.rs | ||
dead_store_elimination.rs | ||
deduce_param_attrs.rs | ||
deduplicate_blocks.rs | ||
deref_separator.rs | ||
dest_prop.rs | ||
dump_mir.rs | ||
early_otherwise_branch.rs | ||
elaborate_box_derefs.rs | ||
elaborate_drops.rs | ||
errors.rs | ||
ffi_unwind_calls.rs | ||
function_item_references.rs | ||
gvn.rs | ||
inline.rs | ||
instsimplify.rs | ||
jump_threading.rs | ||
known_panics_lint.rs | ||
large_enums.rs | ||
lib.rs | ||
lint.rs | ||
lower_intrinsics.rs | ||
lower_slice_len.rs | ||
match_branches.rs | ||
mentioned_items.rs | ||
multiple_return_terminators.rs | ||
normalize_array_len.rs | ||
nrvo.rs | ||
pass_manager.rs | ||
prettify.rs | ||
promote_consts.rs | ||
ref_prop.rs | ||
remove_noop_landing_pads.rs | ||
remove_place_mention.rs | ||
remove_storage_markers.rs | ||
remove_uninit_drops.rs | ||
remove_unneeded_drops.rs | ||
remove_zsts.rs | ||
required_consts.rs | ||
reveal_all.rs | ||
shim.rs | ||
simplify_branches.rs | ||
simplify_comparison_integral.rs | ||
simplify.rs | ||
sroa.rs | ||
ssa.rs | ||
unreachable_enum_branching.rs | ||
unreachable_prop.rs |