diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-03-17 05:47:51 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-17 05:47:51 -0400 |
| commit | e9f6e01b3a0023157c41326b00a6d5e8008e9394 (patch) | |
| tree | 6d0fed72f85ba2d2c2a96f6174efcda54192ef7e /compiler/rustc_mir_transform/src/coverage/mod.rs | |
| parent | 625278bb0e2224bb890243cc7f6af748c11e05b2 (diff) | |
| parent | ae4a4794e75a9317fa9f907dc38ecb177e46c663 (diff) | |
| download | rust-e9f6e01b3a0023157c41326b00a6d5e8008e9394.tar.gz rust-e9f6e01b3a0023157c41326b00a6d5e8008e9394.zip | |
Rollup merge of #138517 - compiler-errors:better-child-capture, r=oli-obk
Improve upvar analysis for deref of child capture
Two fixes to the heuristic I implemented in #123660. As I noted in the code:
> Luckily, if this function 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.
This indeed fixes unnecessary borrowck errors.
r? oli-obk
---
The heuristic is only valid if we deref a `&T`, not a `&mut T` or `Box<T>`, so make sure to check the type. This fixes:
```rust
struct Foo { precise: i32 }
fn mut_ref_inside_mut(f: &mut Foo) {
let x: impl AsyncFn() = async move || {
let y = &f.precise;
};
}
```
Since the capture from `f` to `&f.precise` needs to be treated as a lending borrow from the parent coroutine-closure to the child coroutine.
---
The heuristic is also valid if *any* deref projection in the child capture's projections is a `&T`, but we were only looking at the last one. This ensures that this function is considered not to be lending:
```rust
struct Foo { precise: i32 }
fn ref_inside_mut(f: &mut &Foo) {
let x: impl Fn() -> _ = async move || {
let y = &f.precise;
};
}
```
(Specifically, checking that `impl Fn() -> _` is satisfied is exercising that the coroutine is not considered to be lending.)
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/mod.rs')
0 files changed, 0 insertions, 0 deletions
