rustc_mir_dataflow/move_paths/
abs_domain.rs

1//! The move-analysis portion of borrowck needs to work in an abstract
2//! domain of lifted `Place`s. Most of the `Place` variants fall into a
3//! one-to-one mapping between the concrete and abstract (e.g., a
4//! field-deref on a local variable, `x.field`, has the same meaning
5//! in both domains). Indexed projections are the exception: `a[x]`
6//! needs to be treated as mapping to the same move path as `a[y]` as
7//! well as `a[13]`, etc. So we map these `x`/`y` values to `()`.
8//!
9//! (In theory, the analysis could be extended to work with sets of
10//! paths, so that `a[0]` and `a[13]` could be kept distinct, while
11//! `a[x]` would still overlap them both. But that is not this
12//! representation does today.)
13
14use rustc_middle::mir::{PlaceElem, ProjectionElem, ProjectionKind};
15
16pub(crate) trait Lift {
17    fn lift(&self) -> ProjectionKind;
18}
19
20impl<'tcx> Lift for PlaceElem<'tcx> {
21    fn lift(&self) -> ProjectionKind {
22        match *self {
23            ProjectionElem::Deref => ProjectionElem::Deref,
24            ProjectionElem::Field(f, _ty) => ProjectionElem::Field(f, ()),
25            ProjectionElem::OpaqueCast(_ty) => ProjectionElem::OpaqueCast(()),
26            ProjectionElem::Index(_i) => ProjectionElem::Index(()),
27            ProjectionElem::Subslice { from, to, from_end } => {
28                ProjectionElem::Subslice { from, to, from_end }
29            }
30            ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
31                ProjectionElem::ConstantIndex { offset, min_length, from_end }
32            }
33            ProjectionElem::Downcast(a, u) => ProjectionElem::Downcast(a, u),
34            ProjectionElem::Subtype(_ty) => ProjectionElem::Subtype(()),
35            ProjectionElem::UnwrapUnsafeBinder(_ty) => ProjectionElem::UnwrapUnsafeBinder(()),
36        }
37    }
38}