Skip to content

Commit a53aa39

Browse files
authored
Rollup merge of #147575 - beepster4096:movesubpath, r=oli-obk
Refactor move analysis subpath representation Follow up to rust-lang/rust#147055 This PR does two things: 1. Document/validate move analysis's assumptions about `Subslice` projections 2. Decouple move paths from `ProjectionElem`, using a new enum `MoveSubPath` instead - This would be needed eventually when `ProjectionElem::Deref` is removed I wanted to do even more abstraction, making `MovePathLookup::find` return an iterator to remove the special handling of subslices in borrowck, but that regressed diagnostics and just wasn't worth the complexity.
2 parents ac94a0a + fc3da91 commit a53aa39

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/borrow_check/moves_and_initialization/move_paths.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ We don't actually create a move-path for **every** [`Place`] that gets
6767
used. In particular, if it is illegal to move from a [`Place`], then
6868
there is no need for a [`MovePathIndex`]. Some examples:
6969

70-
- You cannot move from a static variable, so we do not create a [`MovePathIndex`]
71-
for static variables.
7270
- You cannot move an individual element of an array, so if we have e.g. `foo: [String; 3]`,
7371
there would be no move-path for `foo[1]`.
7472
- You cannot move from inside of a borrowed reference, so if we have e.g. `foo: &String`,
@@ -82,6 +80,18 @@ initialized (which lowers overhead).
8280

8381
[`move_path_for`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/move_paths/builder/struct.MoveDataBuilder.html#method.move_path_for
8482

83+
## Projections
84+
85+
Instead of using [`PlaceElem`], projections in move paths are stored as [`MoveSubPath`]s.
86+
Projections that can't be moved out of and projections that can be skipped are not represented.
87+
88+
Subslice projections of arrays (produced by slice patterns) are special; they're turned into
89+
multiple [`ConstantIndex`] subpaths, one for each element in the subslice.
90+
91+
[`PlaceElem`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/type.PlaceElem.html
92+
[`MoveSubPath`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/move_paths/enum.MoveSubPath.html
93+
[`ConstantIndex`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/move_paths/enum.MoveSubPath.html#variant.ConstantIndex
94+
8595
## Looking up a move-path
8696

8797
If you have a [`Place`] and you would like to convert it to a [`MovePathIndex`], you

0 commit comments

Comments
 (0)