stable_mir::mir

Enum ProjectionElem

Source
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

§offset: u64

index or -index (in Python terms), depending on from_end

§min_length: u64

The thing being indexed must be at least this long – otherwise, the projection is UB.

For arrays this is always the exact length.

§from_end: bool

Counting backwards from end? This is always false when indexing an array.

§

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].

Fields

§from: u64
§to: u64
§from_end: bool

Whether to counts from the start or end of the array/slice.

§

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

Source

pub fn ty(&self, place_ty: Ty) -> Result<Ty, Error>

Get the expected type after applying this projection to a given place type.

Source

fn index_ty(ty: Ty) -> Result<Ty, Error>

Source

fn subslice_ty(ty: Ty, from: u64, to: u64, from_end: bool) -> Result<Ty, Error>

Source

fn deref_ty(ty: Ty) -> Result<Ty, Error>

Trait Implementations§

Source§

impl Clone for ProjectionElem

Source§

fn clone(&self) -> ProjectionElem

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProjectionElem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ProjectionElem

Source§

fn eq(&self, other: &ProjectionElem) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ProjectionElem

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for ProjectionElem

Source§

impl StructuralPartialEq for ProjectionElem

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

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 bytes
  • Field: 23 bytes
  • Index: 15 bytes
  • ConstantIndex: 23 bytes
  • Subslice: 23 bytes
  • Downcast: 15 bytes
  • OpaqueCast: 15 bytes
  • Subtype: 15 bytes