1 // Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! The move-analysis portion of borrowck needs to work in an abstract
12 //! domain of lifted Lvalues. Most of the Lvalue variants fall into a
13 //! one-to-one mapping between the concrete and abstract (e.g. a
14 //! field-deref on a local-variable, `x.field`, has the same meaning
15 //! in both domains). Indexed-Projections are the exception: `a[x]`
16 //! needs to be treated as mapping to the same move path as `a[y]` as
17 //! well as `a[13]`, et cetera.
19 //! (In theory the analysis could be extended to work with sets of
20 //! paths, so that `a[0]` and `a[13]` could be kept distinct, while
21 //! `a[x]` would still overlap them both. But that is not this
22 //! representation does today.)
24 use rustc::mir::LvalueElem;
25 use rustc::mir::{Operand, ProjectionElem};
28 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
29 pub struct AbstractOperand;
30 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
31 pub struct AbstractType;
32 pub type AbstractElem<'tcx> =
33 ProjectionElem<'tcx, AbstractOperand, AbstractType>;
37 fn lift(&self) -> Self::Abstract;
39 impl<'tcx> Lift for Operand<'tcx> {
40 type Abstract = AbstractOperand;
41 fn lift(&self) -> Self::Abstract { AbstractOperand }
43 impl<'tcx> Lift for Ty<'tcx> {
44 type Abstract = AbstractType;
45 fn lift(&self) -> Self::Abstract { AbstractType }
47 impl<'tcx> Lift for LvalueElem<'tcx> {
48 type Abstract = AbstractElem<'tcx>;
49 fn lift(&self) -> Self::Abstract {
51 ProjectionElem::Deref =>
52 ProjectionElem::Deref,
53 ProjectionElem::Field(ref f, ty) =>
54 ProjectionElem::Field(f.clone(), ty.lift()),
55 ProjectionElem::Index(ref i) =>
56 ProjectionElem::Index(i.lift()),
57 ProjectionElem::Subslice {from, to} =>
58 ProjectionElem::Subslice { from: from, to: to },
59 ProjectionElem::ConstantIndex {offset,min_length,from_end} =>
60 ProjectionElem::ConstantIndex {
65 ProjectionElem::Downcast(a, u) =>
66 ProjectionElem::Downcast(a.clone(), u.clone()),