Skip to content

Commit b151a5e

Browse files
committed
update movepath docs
1 parent fb1c90a commit b151a5e

File tree

2 files changed

+14
-13
lines changed
  • compiler/rustc_mir_dataflow/src/move_paths
  • src/doc/rustc-dev-guide/src/borrow_check/moves_and_initialization

2 files changed

+14
-13
lines changed

compiler/rustc_mir_dataflow/src/move_paths/mod.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
//! The move-analysis portion of borrowck needs to work in an abstract domain of lifted `Place`s.
2-
//! Most of the `Place` variants fall into a one-to-one mapping between the concrete and abstract
3-
//! (e.g., a field projection on a local variable, `x.field`, has the same meaning in both
4-
//! domains). In other words, all field projections for the same field on the same local do not
5-
//! have meaningfully different types if ever. Indexed projections are the exception: `a[x]` needs
6-
//! to be treated as mapping to the same move path as `a[y]` as well as `a[13]`, etc. So we map
7-
//! these `x`/`y` values to `()`.
8-
//!
9-
//! (In theory, the analysis could be extended to work with sets of paths, so that `a[0]` and
10-
//! `a[13]` could be kept distinct, while `a[x]` would still overlap them both. But that is not
11-
//! what this representation does today.)
1+
//! [`MovePath`]s track the initialization state of places and their sub-paths.
122
133
use std::fmt;
144
use std::ops::{Index, IndexMut};
@@ -399,6 +389,7 @@ impl<'tcx> MoveData<'tcx> {
399389
}
400390
}
401391

392+
/// A projection into a move path producing a child path
402393
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
403394
pub enum MoveSubPath {
404395
Deref,

src/doc/rustc-dev-guide/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)