rust/compiler/rustc_mir_transform/src
Guillaume Gomez 02ee8a8cee
Rollup merge of #123350 - compiler-errors:async-closure-by-move, r=oli-obk
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.
2024-04-05 16:38:51 +02:00
..
coroutine Force move async-closures that are FnOnce to make their inner coroutines also move 2024-04-04 19:44:51 -04:00
coverage coverage: Remove useless constants 2024-04-04 11:07:59 +11:00
inline Auto merge of #123444 - saethlin:const-eval-inline-cycles, r=tmiasko 2024-04-05 04:34:05 +00:00
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 rustc_index: Add a ZERO constant to index types 2024-04-03 19:06:22 +03:00
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 rustc_index: Add a ZERO constant to index types 2024-04-03 19:06:22 +03:00
elaborate_drops.rs
errors.rs Remove MIR unsafe check 2024-04-03 08:50:12 +00:00
ffi_unwind_calls.rs
function_item_references.rs
gvn.rs rustc_index: Add a ZERO constant to index types 2024-04-03 19:06:22 +03:00
inline.rs Rollup merge of #123464 - fmease:rn-has-proj-to-has-aliases, r=compiler-errors 2024-04-04 21:16:58 -04:00
instsimplify.rs
jump_threading.rs
known_panics_lint.rs rustc_index: Add a ZERO constant to index types 2024-04-03 19:06:22 +03:00
large_enums.rs
lib.rs Remove MIR unsafe check 2024-04-03 08:50:12 +00:00
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 rename expose_addr to expose_provenance 2024-04-03 16:00:38 +02:00
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 Auto merge of #123052 - maurer:addr-taken, r=compiler-errors 2024-04-04 06:40:30 +00:00
simplify_branches.rs
simplify_comparison_integral.rs
simplify.rs rustc_index: Add a ZERO constant to index types 2024-04-03 19:06:22 +03:00
sroa.rs
ssa.rs
unreachable_enum_branching.rs
unreachable_prop.rs