]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Rollup merge of #82007 - sexxi-goose:reborrow, r=nikomatsakis
authorDylan DPC <dylan.dpc@gmail.com>
Wed, 17 Feb 2021 22:51:19 +0000 (23:51 +0100)
committerGitHub <noreply@github.com>
Wed, 17 Feb 2021 22:51:19 +0000 (23:51 +0100)
commit0b2f2b941332954c5bd80e61eabce3ee2161a7f5
tree589fbb4f268b617baf3e4ca1099ad7d5fda1c98a
parentcdd93fd3e2f6fb03717db137196a371f6b5c55f7
parentf99e152e5a02d75e5df1a10b33d4e8592cd25fee
Rollup merge of #82007 - sexxi-goose:reborrow, 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: https://github.com/rust-lang/project-rfc-2229/issues/31
r? ````@nikomatsakis````