rust/tests
Matthias Krüger ee73660368
Rollup merge of #123660 - compiler-errors:coroutine-closure-env, r=oli-obk
Make the computation of `coroutine_captures_by_ref_ty` more sophisticated

Currently, we treat all the by-(mut/)ref borrows of a coroutine-closure as having a "closure env" borrowed lifetime.

When we have the given code:
```rust
let x: &'a i32 = ...;
let c = async || {
    let _x = *x;
};
```

Then when we call:
```rust
c()
// which, because `AsyncFn` takes a `&self`, we insert an autoref:
(&c /* &'env {coroutine-closure} */)()
```

We will return a future whose captures contain `&'env i32` instead of `&'a i32`, which is way more restrictive than necessary. We should be able to drop `c` while the future is alive since it's not actually borrowing any data *originating from within* the closure's captures, but since the capture has that `'env` lifetime, this is not possible.

This wouldn't be true, for example, if the closure captured `i32` instead of `&'a i32`, because the `'env` lifetime is actually *necessary* since the data (`i32`) is owned by the closure.

This PR identifies two criteria where we *need* to take the borrow with the closure env lifetime:
1. If the closure borrows data from inside the closure's captures. This is not true if the parent capture is by-ref, OR if the parent capture is by-move and the child capture begins with a deref projection. This is the example described above.
2. If we're dealing with mutable references, since we cannot reborrow `&'env mut &'a mut i32` into `&'a mut i32`, *only* `&'env mut i32`.

See the documentation on `should_reborrow_from_env_of_parent_coroutine_closure` for more info.

**important:** As disclaimer states on that function, luckily, if this heuristic is not correct, then the program is not unsound, since we still borrowck and validate the choices made from this function -- the only side-effect is that the user may receive unnecessary borrowck errors.

Fixes #123241
2024-04-11 16:57:40 +02:00
..
assembly Add support for Arm64EC inline assembly 2024-04-10 10:06:44 -07:00
auxiliary extend extern tests to include FiveU16s 2024-03-17 00:07:42 -04:00
codegen Rollup merge of #122470 - tgross35:f16-f128-step4-libs-min, r=Amanieu 2024-04-11 01:56:23 +02:00
codegen-units Codegen const panic messages as function calls 2024-03-22 09:55:50 -04:00
coverage Eliminate UbCheck for non-standard libraries 2024-03-27 21:02:40 +08:00
coverage-run-rustdoc
debuginfo Add rust-lldb pretty printing for Path and PathBuf 2024-03-29 18:02:26 -06:00
incremental Add missing -Zquery-dep-graph to the spike-neg incr comp tests 2024-04-06 13:36:16 +00:00
mir-opt Auto merge of #122387 - DianQK:re-enable-early-otherwise-branch, r=cjgillot 2024-04-09 01:02:29 +00:00
pretty Add MatchKind member to the Match expr for pretty printing & fmt 2024-03-06 00:35:19 -05:00
run-make Rollup merge of #123612 - kxxt:riscv-target-abi, r=jieyouxu,nikic,DianQK 2024-04-10 04:27:40 +02:00
run-make-fulldeps Soft-destabilize RustcEncodable/RustcDecodable 2024-03-22 13:24:35 -07:00
run-pass-valgrind Add test for Apple's -weak_framework linker argument 2024-03-18 23:27:34 +01:00
rustdoc rustdoc: synthetic auto: filter out clauses from the implementor's ParamEnv 2024-04-08 20:41:04 +02:00
rustdoc-gui rustdoc: update test cases 2024-04-09 20:22:13 -07:00
rustdoc-js Rollup merge of #122247 - notriddle:notriddle/search-unbox-limit, r=GuillaumeGomez 2024-03-14 15:44:32 +01:00
rustdoc-js-std rustdoc-search: add search query syntax Fn(T) -> U 2024-03-11 22:27:22 -07:00
rustdoc-json
rustdoc-ui tests: bless ui and rustdoc-ui tests for ICE messages 2024-04-09 13:58:52 +00:00
ui Rollup merge of #123660 - compiler-errors:coroutine-closure-env, r=oli-obk 2024-04-11 16:57:40 +02:00
ui-fulldeps Rollup merge of #123659 - celinval:smir-fix-intrinsic, r=oli-obk 2024-04-10 16:15:23 +02:00
COMPILER_TESTS.md