pub enum ProjectionElem {
Deref,
Field(FieldIdx, Ty),
Index(Local),
ConstantIndex {
offset: u64,
min_length: u64,
from_end: bool,
},
Subslice {
from: u64,
to: u64,
from_end: bool,
},
Downcast(VariantIdx),
OpaqueCast(Ty),
Subtype(Ty),
}
Variants§
Deref
Dereference projections (e.g. *_1
) project to the address referenced by the base place.
Field(FieldIdx, Ty)
A field projection (e.g., f
in _1.f
) project to a field in the base place. The field is
referenced by source-order index rather than the name of the field. The fields type is also
given.
Index(Local)
Index into a slice/array. The value of the index is computed at runtime using the V
argument.
Note that this does not also dereference, and so it does not exactly correspond to slice indexing in Rust. In other words, in the below Rust code:
let x = &[1, 2, 3, 4];
let i = 2;
x[i];
The x[i]
is turned into a Deref
followed by an Index
, not just an Index
. The same
thing is true of the ConstantIndex
and Subslice
projections below.
ConstantIndex
Index into a slice/array given by offsets.
These indices are generated by slice patterns. Easiest to explain by example:
[X, _, .._, _, _] => { offset: 0, min_length: 4, from_end: false },
[_, X, .._, _, _] => { offset: 1, min_length: 4, from_end: false },
[_, _, .._, X, _] => { offset: 2, min_length: 4, from_end: true },
[_, _, .._, _, X] => { offset: 1, min_length: 4, from_end: true },
Fields
Subslice
Projects a slice from the base place.
These indices are generated by slice patterns. If from_end
is true, this represents
slice[from..slice.len() - to]
. Otherwise it represents array[from..to]
.
Downcast(VariantIdx)
“Downcast” to a variant of an enum or a coroutine.
OpaqueCast(Ty)
Like an explicit cast from an opaque type to a concrete type, but without requiring an intermediate variable.
Subtype(Ty)
A Subtype(T)
projection is applied to any StatementKind::Assign
where
type of lvalue doesn’t match the type of rvalue, the primary goal is making subtyping
explicit during optimizations and codegen.
This projection doesn’t impact the runtime behavior of the program except for potentially changing some type metadata of the interpreter or codegen backend.
Implementations§
Source§impl ProjectionElem
impl ProjectionElem
Sourcepub fn ty(&self, place_ty: Ty) -> Result<Ty, Error>
pub fn ty(&self, place_ty: Ty) -> Result<Ty, Error>
Get the expected type after applying this projection to a given place type.
fn index_ty(ty: Ty) -> Result<Ty, Error>
fn subslice_ty(ty: Ty, from: u64, to: u64, from_end: bool) -> Result<Ty, Error>
fn deref_ty(ty: Ty) -> Result<Ty, Error>
Trait Implementations§
Source§impl Clone for ProjectionElem
impl Clone for ProjectionElem
Source§fn clone(&self) -> ProjectionElem
fn clone(&self) -> ProjectionElem
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ProjectionElem
impl Debug for ProjectionElem
Source§impl PartialEq for ProjectionElem
impl PartialEq for ProjectionElem
Source§impl Serialize for ProjectionElem
impl Serialize for ProjectionElem
impl Eq for ProjectionElem
impl StructuralPartialEq for ProjectionElem
Auto Trait Implementations§
impl Freeze for ProjectionElem
impl RefUnwindSafe for ProjectionElem
impl Send for ProjectionElem
impl Sync for ProjectionElem
impl Unpin for ProjectionElem
impl UnwindSafe for ProjectionElem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 24 bytes
Size for each variant:
Deref
: 0 bytesField
: 23 bytesIndex
: 15 bytesConstantIndex
: 23 bytesSubslice
: 23 bytesDowncast
: 15 bytesOpaqueCast
: 15 bytesSubtype
: 15 bytes