rust/tests/ui/async-await/async-closures
Matthias Krüger 6c898d2b03
Rollup merge of #129101 - compiler-errors:deref-on-parent-by-ref, r=lcnr
Fix projections when parent capture is by-ref but child capture is by-value in the `ByMoveBody` pass

This fixes a somewhat strange bug where we build the incorrect MIR in #129074. This one is weird, but I don't expect it to actually matter in practice since it almost certainly results in a move error in borrowck. However, let's not ICE.

Given the code:

```
#![feature(async_closure)]

// NOT copy.
struct Ty;

fn hello(x: &Ty) {
    let c = async || {
        *x;
        //~^ ERROR cannot move out of `*x` which is behind a shared reference
    };
}

fn main() {}
```

The parent coroutine-closure captures `x: &Ty` by-ref, resulting in an upvar of `&&Ty`. The child coroutine captures `x` by-value, resulting in an upvar of `&Ty`. When constructing the by-move body for the coroutine-closure, we weren't applying an additional deref projection to convert the parent capture into the child capture, resulting in an type error in assignment, which is a validation ICE.

As I said above, this only occurs (AFAICT) in code that eventually results in an error, because it is only triggered by HIR that attempts to move a non-copy value out of a ref. This doesn't occur if `Ty` is `Copy`, since we'd instead capture `x` by-ref in the child coroutine.

Fixes #129074
2024-08-15 19:32:37 +02:00
..
auxiliary [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
ambiguous-arg.rs Propagate errors rather than using return_if_err 2024-05-12 12:50:18 -04:00
ambiguous-arg.stderr Propagate errors rather than using return_if_err 2024-05-12 12:50:18 -04:00
arg-mismatch.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
arg-mismatch.stderr Add some tests 2024-02-06 02:22:58 +00:00
async-fn-mut-for-async-fn.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
async-fn-once-for-async-fn.rs Flesh out a few more tests 2024-02-27 17:39:20 +00:00
await-inference-guidance.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
box-deref-in-debuginfo.rs Stop doing weird index stuff in ElaborateBoxDerefs 2024-08-02 17:45:55 -04:00
brand.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
captures.rs Force move async-closures that are FnOnce to make their inner coroutines also move 2024-04-04 19:44:51 -04:00
captures.run.stdout Force move async-closures that are FnOnce to make their inner coroutines also move 2024-04-04 19:44:51 -04:00
clone-closure.rs Make coroutine-closures possible to be cloned 2024-07-26 12:53:53 -04:00
clone-closure.run.stdout Make coroutine-closures possible to be cloned 2024-07-26 12:53:53 -04:00
constrained-but-no-upvars-yet.rs Make all tests in async dir build-pass, adjust implements-fnmut test to begin ICEing during codegen 2024-06-29 17:38:02 -04:00
def-path.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
def-path.stderr Only split by-ref/by-move futures for async closures 2024-03-19 16:59:23 -04:00
different-projection-lengths-for-different-upvars.rs Only assert for child/parent projection compatibility AFTER checking that theyre coming from the same place 2024-04-10 10:13:24 -04:00
dont-ice-when-body-tainted-by-errors.rs Don't do coroutine-closure-specific upvar analysis if tainted by errors 2024-04-12 12:14:29 -04:00
dont-ice-when-body-tainted-by-errors.stderr Don't do coroutine-closure-specific upvar analysis if tainted by errors 2024-04-12 12:14:29 -04:00
drop.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
drop.run.stdout Fix drop shim for AsyncFnOnce closure, AsyncFnMut shim for AsyncFn closure 2024-02-06 02:22:58 +00:00
fn-exception-target-features.rs Don't implement AsyncFn for FnDef/FnPtr that wouldnt implement Fn 2024-08-08 14:07:31 -04:00
fn-exception-target-features.stderr Don't implement AsyncFn for FnDef/FnPtr that wouldnt implement Fn 2024-08-08 14:07:31 -04:00
fn-exception.rs Don't implement AsyncFn for FnDef/FnPtr that wouldnt implement Fn 2024-08-08 14:07:31 -04:00
fn-exception.stderr Don't implement AsyncFn for FnDef/FnPtr that wouldnt implement Fn 2024-08-08 14:07:31 -04:00
force-move-due-to-actually-fnonce.rs Make all tests in async dir build-pass, adjust implements-fnmut test to begin ICEing during codegen 2024-06-29 17:38:02 -04:00
force-move-due-to-inferred-kind.rs Make all tests in async dir build-pass, adjust implements-fnmut test to begin ICEing during codegen 2024-06-29 17:38:02 -04:00
foreign.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
higher-ranked-return.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
higher-ranked-return.stderr Add some tests 2024-02-06 02:22:58 +00:00
higher-ranked.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
implements-fnmut.rs Make all tests in async dir build-pass, adjust implements-fnmut test to begin ICEing during codegen 2024-06-29 17:38:02 -04:00
is-fn.rs Ignore tests w/ current/next revisions from compare-mode=next-solver 2024-03-10 21:18:41 -04:00
is-not-fn.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
is-not-fn.stderr Print kind of coroutine closure 2024-02-10 23:18:01 +00:00
lint-closure-returning-async-block.rs Make it into a structured suggestion, maybe-incorrect 2024-06-28 20:16:35 -04:00
lint-closure-returning-async-block.stderr Make it into a structured suggestion, maybe-incorrect 2024-06-28 20:16:35 -04:00
mangle.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
moro-example.rs Make the computation of coroutine_captures_by_ref_ty more sophisticated 2024-04-10 13:39:53 -04:00
move-consuming-capture.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
move-consuming-capture.stderr Make coroutine-closures possible to be cloned 2024-07-26 12:53:53 -04:00
move-is-async-fn.rs Flesh out a few more tests 2024-02-27 17:39:20 +00:00
move-out-of-ref.rs Fix projections when parent capture is by-ref 2024-08-14 13:24:07 -04:00
move-out-of-ref.stderr Fix projections when parent capture is by-ref 2024-08-14 13:24:07 -04:00
mut-ref-reborrow.rs Account for an additional reborrow inserted by UniqueImmBorrow and MutBorrow 2024-04-05 17:35:03 -04:00
mutate.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
no-borrow-from-env.rs Make the computation of coroutine_captures_by_ref_ty more sophisticated 2024-04-10 13:39:53 -04:00
non-copy-arg-does-not-force-inner-move.rs Skip over args when determining if coroutine-closure's inner coroutine consumes its upvars 2024-08-01 18:46:26 -04:00
not-clone-closure.rs Make coroutine-closures possible to be cloned 2024-07-26 12:53:53 -04:00
not-clone-closure.stderr Make coroutine-closures possible to be cloned 2024-07-26 12:53:53 -04:00
not-fn.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
not-fn.stderr make better async fn kind errors 2024-02-15 15:59:35 +00:00
not-lending.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
not-lending.stderr Add some tests 2024-02-06 02:22:58 +00:00
once.rs Ignore tests w/ current/next revisions from compare-mode=next-solver 2024-03-10 21:18:41 -04:00
overlapping-projs.rs Check the base of the place too! 2024-04-05 16:48:45 -04:00
overlapping-projs.run.stdout Check the base of the place too! 2024-04-05 16:48:45 -04:00
precise-captures.call_once.run.stdout Rework the ByMoveBody shim to actually work correctly 2024-04-05 15:28:13 -04:00
precise-captures.call.run.stdout Rework the ByMoveBody shim to actually work correctly 2024-04-05 15:28:13 -04:00
precise-captures.force_once.run.stdout Rework the ByMoveBody shim to actually work correctly 2024-04-05 15:28:13 -04:00
precise-captures.rs Rework the ByMoveBody shim to actually work correctly 2024-04-05 15:28:13 -04:00
refd.rs Flesh out a few more tests 2024-02-27 17:39:20 +00:00
return-type-mismatch.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
return-type-mismatch.stderr Add some tests 2024-02-06 02:22:58 +00:00
sig-from-bare-fn.rs Infer async closure args from Fn bound even if there is no corresponding Future bound 2024-08-14 15:33:03 -04:00
signature-deduction.rs Make all tests in async dir build-pass, adjust implements-fnmut test to begin ICEing during codegen 2024-06-29 17:38:02 -04:00
signature-inference-from-two-part-bound.rs Infer async closure signature from old-style two-part Fn + Future bounds 2024-07-08 12:56:54 -04:00
tainted-body.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
tainted-body.stderr Don't ICE in ByMoveBody when coroutine is tainted 2024-02-09 00:36:30 +00:00
truncated-fields-when-imm.rs Actually, stop making any assumption about the projections applied to the upvar 2024-04-08 19:47:52 -04:00
without-precise-captures-we-are-powerless.rs Make coroutine-closures possible to be cloned 2024-07-26 12:53:53 -04:00
without-precise-captures-we-are-powerless.stderr Suppress useless clone suggestion 2024-07-26 12:53:55 -04:00
wrong-fn-kind.rs Actually use the inferred ClosureKind from signature inference in coroutine-closures 2024-04-04 19:44:35 -04:00
wrong-fn-kind.stderr Tighten spans for async blocks 2024-06-27 15:19:08 -04:00