Implement reborrow for closure captures#82007
Conversation
|
Updates src/tools/cargo. cc @ehuss |
|
|
Hmm fixing the cargo.lock and submodule issues 🙃 |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
A bit shorter with Iterator::position:
| for (i, proj) in place.projections.iter().enumerate() { | |
| match proj.kind { | |
| ProjectionKind::Deref => { | |
| // We only drop Derefs in case of move closures | |
| // There might be an index projection or raw ptr ahead, so we don't stop here. | |
| place.projections.truncate(i); | |
| return place; | |
| } | |
| _ => {} | |
| } | |
| } | |
| place | |
| if let Some(i) = place.projections.iter().position(|proj| proj.kind == ProjectionKind::Deref) { | |
| // We only drop Derefs in case of move closures | |
| // There might be an index projection or raw ptr ahead, so we don't stop here. | |
| place.projections.truncate(i); | |
| } | |
| place |
Edit: Removed unhelpful temporary.
There was a problem hiding this comment.
Thank you, didn't know this was a thing. I'll update the PR at once, after the PR's been completely reviewed
|
This looks great. Go ahead and change to @bors delegate+ |
|
✌️ @arora-aman can now approve this pull request |
|
After that you can tell bors r=nikomatsakis |
|
@bors r=nikomatsakis |
|
📌 Commit 20788d666da8881ff3207e18967402c8e70bb7ed has been approved by |
|
☔ The latest upstream changes (presumably #82103) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@bors r=nikomatsakis |
|
📌 Commit f99e152 has been approved by |
Implement reborrow for closure captures The strategy for captures is detailed here with examples: https://hackmd.io/PzxYMPY4RF-B9iH9uj9GTA Key points: - We only need to reborrow a capture in case of move closures. - If we mutate something via a `&mut` we store it as a `MutBorrow`/`UniqueMuBorrow` of the path containing the `&mut`, - Similarly, if it's read via `&` ref we just store it as a `ImmBorrow` of the path containing the `&` ref. - If a path doesn't deref a `&mut`, `&`, then that path is captured by Move. - If the use of a path results in a move when the closure is called, then that path is truncated before any deref and the truncated path is moved into the closure. - In the case of non-move closure if a use of a path results in a move, then the path is truncated before any deref and the truncated path is moved into the closure. Note that the implementation differs a bit from the document to allow for truncated path to be used in the ClosureKind analysis that happens as part of the first capture analysis pass. Closes: rust-lang/project-rfc-2229#31 r? `@nikomatsakis`
Implement reborrow for closure captures The strategy for captures is detailed here with examples: https://hackmd.io/PzxYMPY4RF-B9iH9uj9GTA Key points: - We only need to reborrow a capture in case of move closures. - If we mutate something via a `&mut` we store it as a `MutBorrow`/`UniqueMuBorrow` of the path containing the `&mut`, - Similarly, if it's read via `&` ref we just store it as a `ImmBorrow` of the path containing the `&` ref. - If a path doesn't deref a `&mut`, `&`, then that path is captured by Move. - If the use of a path results in a move when the closure is called, then that path is truncated before any deref and the truncated path is moved into the closure. - In the case of non-move closure if a use of a path results in a move, then the path is truncated before any deref and the truncated path is moved into the closure. Note that the implementation differs a bit from the document to allow for truncated path to be used in the ClosureKind analysis that happens as part of the first capture analysis pass. Closes: rust-lang/project-rfc-2229#31 r? ``@nikomatsakis``
Implement reborrow for closure captures The strategy for captures is detailed here with examples: https://hackmd.io/PzxYMPY4RF-B9iH9uj9GTA Key points: - We only need to reborrow a capture in case of move closures. - If we mutate something via a `&mut` we store it as a `MutBorrow`/`UniqueMuBorrow` of the path containing the `&mut`, - Similarly, if it's read via `&` ref we just store it as a `ImmBorrow` of the path containing the `&` ref. - If a path doesn't deref a `&mut`, `&`, then that path is captured by Move. - If the use of a path results in a move when the closure is called, then that path is truncated before any deref and the truncated path is moved into the closure. - In the case of non-move closure if a use of a path results in a move, then the path is truncated before any deref and the truncated path is moved into the closure. Note that the implementation differs a bit from the document to allow for truncated path to be used in the ClosureKind analysis that happens as part of the first capture analysis pass. Closes: rust-lang/project-rfc-2229#31 r? ```@nikomatsakis```
Rollup of 8 pull requests Successful merges: - rust-lang#77728 (Expose force_quotes on Windows.) - rust-lang#80572 (Add a `Result::into_ok_or_err` method to extract a `T` from `Result<T, T>`) - rust-lang#81860 (Fix SourceMap::start_point) - rust-lang#81869 (Simplify pattern grammar, improve or-pattern diagnostics) - rust-lang#81898 (Fix debug information for function arguments of type &str or slice.) - rust-lang#81972 (Placeholder lifetime error cleanup) - rust-lang#82007 (Implement reborrow for closure captures) - rust-lang#82021 (Spell out nested Self type in lint message) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
|
Is this visible in the stable language? If so, does it need |
|
This is behind the If I recall correcly this increases the precision of the capture (for non-unsafe code) which was restricted while trying to support move of a path that uses accesses reference in #80092. That PR was 1.51 based on the associated milestone. |
|
relnotes usually sticks to stable stuff |
The strategy for captures is detailed here with examples: https://hackmd.io/PzxYMPY4RF-B9iH9uj9GTA
Key points:
We only need to reborrow a capture in case of move closures.
&mutwe store it as aMutBorrow/UniqueMuBorrowof the path containing the&mut,&ref we just store it as aImmBorrowof the path containing the&ref.&mut,&, then that path is captured by Move.In the case of non-move closure if a use of a path results in a move, then the path is truncated before any deref and the truncated path is moved into the closure.
Note that the implementation differs a bit from the document to allow for truncated path to be used in the ClosureKind analysis that happens as part of the first capture analysis pass.
Closes: rust-lang/project-rfc-2229#31
r? @nikomatsakis