pub enum ProjectionElem {
Deref,
Field(Option<VariantId>, FieldId),
PtrMetadata,
Index {
offset: Box<Operand>,
from_end: bool,
},
Subslice {
from: Box<Operand>,
to: Box<Operand>,
from_end: bool,
},
Offset {
bytes: Box<Operand>,
in_bounds: bool,
ty: Ty,
ty_is_sized: Option<TraitRef>,
},
}Expand description
Projects a place to a subplace.
Variants§
Deref
Dereference a shared/mutable reference, a box, or a raw pointer.
Field(Option<VariantId>, FieldId)
Project to the field of an ADT (struct, union, or enum).
PtrMetadata
A built-in pointer (a reference, raw pointer, or Box) in Rust is always a fat pointer: it
contains an address and metadata for the pointed-to place. This metadata is empty for sized
types, it’s the length for slices, and the vtable for dyn Trait.
We consider such pointers to be like a struct with two fields; this represent access to the metadata “field”.
Index
MIR imposes that the argument to an index projection be a local variable, meaning that even constant indices into arrays are let-bound as separate variables. We eliminate this variant in a micro-pass for LLBC.
Subslice
Take a subslice of a slice or array. If from_end is true this is
slice[from..slice.len() - to], otherwise this is slice[from..to].
We eliminate this variant in a micro-pass for LLBC.
Offset
For a place p, p.offset(n) is the place located n bytes after p, where n is a
signed or unsigned integer. This projection may go out of bounds of the original place, e.g.
if we initially had a *const T pointing into an array. If in_bounds is true the offset
must not overflow and must stay within the original allocation, otherwise it uses wrapping
arithmetic around the address space and may go outside the allocation (just like
<*const T>::offset vs <*const T>::wrapping_offset).
An offset may change the type of the place, like a transmute: ty is the type of the
resulting place, which is T: Sized as proven by ty_is_sized.
Implementations§
Source§impl ProjectionElem
impl ProjectionElem
Sourcepub fn is_deref(&self) -> bool
pub fn is_deref(&self) -> bool
Returns true if this is a ProjectionElem::Deref, otherwise false
Sourcepub fn is_field(&self) -> bool
pub fn is_field(&self) -> bool
Returns true if this is a ProjectionElem::Field, otherwise false
Sourcepub fn as_field_mut(&mut self) -> Option<(&mut Option<VariantId>, &mut FieldId)>
pub fn as_field_mut(&mut self) -> Option<(&mut Option<VariantId>, &mut FieldId)>
Optionally returns mutable references to the inner fields if this is a ProjectionElem::Field, otherwise None
Sourcepub fn as_field(&self) -> Option<(&Option<VariantId>, &FieldId)>
pub fn as_field(&self) -> Option<(&Option<VariantId>, &FieldId)>
Optionally returns references to the inner fields if this is a ProjectionElem::Field, otherwise None
Sourcepub fn into_field(self) -> Result<(Option<VariantId>, FieldId), Self>
pub fn into_field(self) -> Result<(Option<VariantId>, FieldId), Self>
Returns the inner fields if this is a ProjectionElem::Field, otherwise returns back the enum in the Err case of the result
Sourcepub unsafe fn into_field_unchecked(self) -> (Option<VariantId>, FieldId)
pub unsafe fn into_field_unchecked(self) -> (Option<VariantId>, FieldId)
Unchecked return of the inner fields of ProjectionElem::Field.
§Safety
Results in undefined behavior when it is the incorrect variant.
Sourcepub unsafe fn as_field_unchecked(&self) -> (&Option<VariantId>, &FieldId)
pub unsafe fn as_field_unchecked(&self) -> (&Option<VariantId>, &FieldId)
Unchecked reference of the inner fields of ProjectionElem::Field.
§Safety
Results in undefined behavior when it is the incorrect variant.
Sourcepub unsafe fn as_field_mut_unchecked(
&mut self,
) -> (&mut Option<VariantId>, &mut FieldId)
pub unsafe fn as_field_mut_unchecked( &mut self, ) -> (&mut Option<VariantId>, &mut FieldId)
Unchecked mutable reference of the inner fields of ProjectionElem::Field.
§Safety
Results in undefined behavior when it is the incorrect variant.
Sourcepub fn is_ptr_metadata(&self) -> bool
pub fn is_ptr_metadata(&self) -> bool
Returns true if this is a ProjectionElem::PtrMetadata, otherwise false
Sourcepub fn is_index(&self) -> bool
pub fn is_index(&self) -> bool
Returns true if this is a ProjectionElem::Index, otherwise false
Sourcepub fn as_index_mut(&mut self) -> Option<(&mut Box<Operand>, &mut bool)>
pub fn as_index_mut(&mut self) -> Option<(&mut Box<Operand>, &mut bool)>
Optionally returns mutable references to the inner fields if this is a ProjectionElem::Index, otherwise None
Sourcepub fn as_index(&self) -> Option<(&Box<Operand>, &bool)>
pub fn as_index(&self) -> Option<(&Box<Operand>, &bool)>
Optionally returns references to the inner fields if this is a ProjectionElem::Index, otherwise None
Sourcepub fn into_index(self) -> Result<(Box<Operand>, bool), Self>
pub fn into_index(self) -> Result<(Box<Operand>, bool), Self>
Returns the inner fields if this is a ProjectionElem::Index, otherwise returns back the enum in the Err case of the result
Sourcepub unsafe fn into_index_unchecked(self) -> (Box<Operand>, bool)
pub unsafe fn into_index_unchecked(self) -> (Box<Operand>, bool)
Unchecked return of the inner fields of ProjectionElem::Index.
§Safety
Results in undefined behavior when it is the incorrect variant.
Sourcepub unsafe fn as_index_unchecked(&self) -> (&Box<Operand>, &bool)
pub unsafe fn as_index_unchecked(&self) -> (&Box<Operand>, &bool)
Unchecked reference of the inner fields of ProjectionElem::Index.
§Safety
Results in undefined behavior when it is the incorrect variant.
Sourcepub unsafe fn as_index_mut_unchecked(
&mut self,
) -> (&mut Box<Operand>, &mut bool)
pub unsafe fn as_index_mut_unchecked( &mut self, ) -> (&mut Box<Operand>, &mut bool)
Unchecked mutable reference of the inner fields of ProjectionElem::Index.
§Safety
Results in undefined behavior when it is the incorrect variant.
Sourcepub fn is_subslice(&self) -> bool
pub fn is_subslice(&self) -> bool
Returns true if this is a ProjectionElem::Subslice, otherwise false
Sourcepub fn as_subslice_mut(
&mut self,
) -> Option<(&mut Box<Operand>, &mut Box<Operand>, &mut bool)>
pub fn as_subslice_mut( &mut self, ) -> Option<(&mut Box<Operand>, &mut Box<Operand>, &mut bool)>
Optionally returns mutable references to the inner fields if this is a ProjectionElem::Subslice, otherwise None
Sourcepub fn as_subslice(&self) -> Option<(&Box<Operand>, &Box<Operand>, &bool)>
pub fn as_subslice(&self) -> Option<(&Box<Operand>, &Box<Operand>, &bool)>
Optionally returns references to the inner fields if this is a ProjectionElem::Subslice, otherwise None
Sourcepub fn into_subslice(self) -> Result<(Box<Operand>, Box<Operand>, bool), Self>
pub fn into_subslice(self) -> Result<(Box<Operand>, Box<Operand>, bool), Self>
Returns the inner fields if this is a ProjectionElem::Subslice, otherwise returns back the enum in the Err case of the result
Sourcepub unsafe fn into_subslice_unchecked(
self,
) -> (Box<Operand>, Box<Operand>, bool)
pub unsafe fn into_subslice_unchecked( self, ) -> (Box<Operand>, Box<Operand>, bool)
Unchecked return of the inner fields of ProjectionElem::Subslice.
§Safety
Results in undefined behavior when it is the incorrect variant.
Sourcepub unsafe fn as_subslice_unchecked(
&self,
) -> (&Box<Operand>, &Box<Operand>, &bool)
pub unsafe fn as_subslice_unchecked( &self, ) -> (&Box<Operand>, &Box<Operand>, &bool)
Unchecked reference of the inner fields of ProjectionElem::Subslice.
§Safety
Results in undefined behavior when it is the incorrect variant.
Sourcepub unsafe fn as_subslice_mut_unchecked(
&mut self,
) -> (&mut Box<Operand>, &mut Box<Operand>, &mut bool)
pub unsafe fn as_subslice_mut_unchecked( &mut self, ) -> (&mut Box<Operand>, &mut Box<Operand>, &mut bool)
Unchecked mutable reference of the inner fields of ProjectionElem::Subslice.
§Safety
Results in undefined behavior when it is the incorrect variant.
Sourcepub fn is_offset(&self) -> bool
pub fn is_offset(&self) -> bool
Returns true if this is a ProjectionElem::Offset, otherwise false
Sourcepub fn as_offset_mut(
&mut self,
) -> Option<(&mut Box<Operand>, &mut bool, &mut Ty, &mut Option<TraitRef>)>
pub fn as_offset_mut( &mut self, ) -> Option<(&mut Box<Operand>, &mut bool, &mut Ty, &mut Option<TraitRef>)>
Optionally returns mutable references to the inner fields if this is a ProjectionElem::Offset, otherwise None
Sourcepub fn as_offset(
&self,
) -> Option<(&Box<Operand>, &bool, &Ty, &Option<TraitRef>)>
pub fn as_offset( &self, ) -> Option<(&Box<Operand>, &bool, &Ty, &Option<TraitRef>)>
Optionally returns references to the inner fields if this is a ProjectionElem::Offset, otherwise None
Sourcepub fn into_offset(
self,
) -> Result<(Box<Operand>, bool, Ty, Option<TraitRef>), Self>
pub fn into_offset( self, ) -> Result<(Box<Operand>, bool, Ty, Option<TraitRef>), Self>
Returns the inner fields if this is a ProjectionElem::Offset, otherwise returns back the enum in the Err case of the result
Sourcepub unsafe fn into_offset_unchecked(
self,
) -> (Box<Operand>, bool, Ty, Option<TraitRef>)
pub unsafe fn into_offset_unchecked( self, ) -> (Box<Operand>, bool, Ty, Option<TraitRef>)
Unchecked return of the inner fields of ProjectionElem::Offset.
§Safety
Results in undefined behavior when it is the incorrect variant.
Source§impl ProjectionElem
impl ProjectionElem
Sourcepub fn project_type(&self, krate: &TranslatedCrate, ty: &Ty) -> Option<Ty>
pub fn project_type(&self, krate: &TranslatedCrate, ty: &Ty) -> Option<Ty>
Compute the type obtained when applying the current projection to a place of type ty.
Trait Implementations§
Source§impl AstVisitable for ProjectionElem
impl AstVisitable for ProjectionElem
Source§fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>
fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner.Source§fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>
fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner.Source§fn drive_two<V: ZipAst>(&self, other: &Self, v: &mut V) -> ControlFlow<V::Break>
fn drive_two<V: ZipAst>(&self, other: &Self, v: &mut V) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner.Source§fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T))where
Self: Sized,
fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T))where
Self: Sized,
self, in pre-order traversal.Source§fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T))where
Self: Sized,
fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T))where
Self: Sized,
self, in pre-order traversal.Source§impl BodyVisitable for ProjectionElem
impl BodyVisitable for ProjectionElem
Source§fn drive_body<V: VisitBody>(&self, v: &mut V) -> ControlFlow<V::Break>
fn drive_body<V: VisitBody>(&self, v: &mut V) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner.Source§fn drive_body_mut<V: VisitBodyMut>(
&mut self,
v: &mut V,
) -> ControlFlow<V::Break>
fn drive_body_mut<V: VisitBodyMut>( &mut self, v: &mut V, ) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner.Source§fn dyn_visit_in_body<T: BodyVisitable>(&self, f: impl FnMut(&T))where
Self: Sized,
fn dyn_visit_in_body<T: BodyVisitable>(&self, f: impl FnMut(&T))where
Self: Sized,
self, in pre-order traversal.Source§fn dyn_visit_in_body_mut<T: BodyVisitable>(&mut self, f: impl FnMut(&mut T))where
Self: Sized,
fn dyn_visit_in_body_mut<T: BodyVisitable>(&mut self, f: impl FnMut(&mut T))where
Self: Sized,
self, in pre-order traversal.Source§impl Clone for ProjectionElem
impl Clone for ProjectionElem
Source§fn clone(&self) -> ProjectionElem
fn clone(&self) -> ProjectionElem
1.0.0 (const: unstable) · 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<'de, __State: ?Sized> DeserializeState<'de, __State> for ProjectionElem
impl<'de, __State: ?Sized> DeserializeState<'de, __State> for ProjectionElem
fn deserialize_state<__D>(
__state: &__State,
__deserializer: __D,
) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'s, V> Drive<'s, V> for ProjectionElem
impl<'s, V> Drive<'s, V> for ProjectionElem
Source§fn drive_inner(&'s self, visitor: &mut V) -> ControlFlow<V::Break>
fn drive_inner(&'s self, visitor: &mut V) -> ControlFlow<V::Break>
v.visit() on the immediate contents of self.Source§impl<'s, V> DriveMut<'s, V> for ProjectionElem
impl<'s, V> DriveMut<'s, V> for ProjectionElem
Source§fn drive_inner_mut(&'s mut self, visitor: &mut V) -> ControlFlow<V::Break>
fn drive_inner_mut(&'s mut self, visitor: &mut V) -> ControlFlow<V::Break>
v.visit() on the immediate contents of self.Source§impl<'s, V> DriveTwo<'s, V> for ProjectionElem
impl<'s, V> DriveTwo<'s, V> for ProjectionElem
Source§fn drive_two_inner(
&'s self,
other: &'s Self,
visitor: &mut V,
) -> ControlFlow<V::Break>
fn drive_two_inner( &'s self, other: &'s Self, visitor: &mut V, ) -> ControlFlow<V::Break>
v.visit() on the immediate contents of self and other, if they correspond. If
the values don’t match up, this returns Break(Default::default()).impl Eq for ProjectionElem
Source§impl PartialEq for ProjectionElem
impl PartialEq for ProjectionElem
Source§impl<__State: ?Sized> SerializeState<__State> for ProjectionElem
impl<__State: ?Sized> SerializeState<__State> for ProjectionElem
fn serialize_state<__S>(
&self,
__state: &__State,
__serializer: __S,
) -> Result<__S::Ok, __S::Error>where
__S: Serializer,
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 UnsafeUnpin 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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> Mappable for T
Source§impl<T> TyVisitable for Twhere
T: AstVisitable,
impl<T> TyVisitable for Twhere
T: AstVisitable,
Source§fn type_info(&self) -> TypeInfo
fn type_info(&self) -> TypeInfo
TypeInfo.Source§fn visit_vars(&mut self, v: &mut impl VarsVisitor)
fn visit_vars(&mut self, v: &mut impl VarsVisitor)
self, as seen from the outside of self. This means
that any variable bound inside self will be skipped, and all the seen De Bruijn indices
will count from the outside of self.Source§fn substitute(self, generics: &GenericArgs) -> Self
fn substitute(self, generics: &GenericArgs) -> Self
self by replacing them with the provided values.
Note: if self is an item that comes from a TraitDecl, you must use
substitute_with_self or substitute_inner_binder, otherwise you’ll get panics.Source§fn substitute_inner_binder(self, generics: &GenericArgs) -> Self
fn substitute_inner_binder(self, generics: &GenericArgs) -> Self
self by replacing them with the provided values.
This is appropriate when substituting an inner binder.Source§fn substitute_explicits(self, generics: &GenericArgs) -> Self
fn substitute_explicits(self, generics: &GenericArgs) -> Self
Source§fn substitute_with_self(
self,
generics: &GenericArgs,
self_ref: &TraitRefKind,
) -> Self
fn substitute_with_self( self, generics: &GenericArgs, self_ref: &TraitRefKind, ) -> Self
TraitRefKind::SelfId trait ref.Source§fn substitute_with_tref(self, tref: &TraitRef) -> Self
fn substitute_with_tref(self, tref: &TraitRef) -> Self
TraitRefKind::SelfId trait ref.Source§fn try_substitute_with_tref(
self,
tref: &TraitRef,
) -> Result<Self, GenericsMismatch>
fn try_substitute_with_tref( self, tref: &TraitRef, ) -> Result<Self, GenericsMismatch>
TraitRefKind::SelfId trait ref.fn try_substitute( self, generics: &GenericArgs, ) -> Result<Self, GenericsMismatch>
fn try_substitute_with_self( self, generics: &GenericArgs, self_ref: &TraitRefKind, ) -> Result<Self, GenericsMismatch>
Source§fn move_under_binder(self) -> Self
fn move_under_binder(self) -> Self
Source§fn move_under_binders(self, depth: DeBruijnId) -> Self
fn move_under_binders(self, depth: DeBruijnId) -> Self
depth binders.Source§fn move_from_under_binder(self) -> Option<Self>
fn move_from_under_binder(self) -> Option<Self>
Source§fn move_from_under_binders(self, depth: DeBruijnId) -> Option<Self>
fn move_from_under_binders(self, depth: DeBruijnId) -> Option<Self>
depth binders. Returns None if it contains a variable bound in
one of these depth binders.Source§fn visit_db_id<B>(
&mut self,
f: impl FnMut(&mut DeBruijnId) -> ControlFlow<B>,
) -> ControlFlow<B>
fn visit_db_id<B>( &mut self, f: impl FnMut(&mut DeBruijnId) -> ControlFlow<B>, ) -> ControlFlow<B>
self, as seen from the outside of self. This means
that any variable bound inside self will be skipped, and all the seen indices will count
from the outside of self.Source§fn has_escaping_region_var(&self) -> bool
fn has_escaping_region_var(&self) -> bool
Source§fn collect_regions(&self) -> SeqHashSet<Region>
fn collect_regions(&self) -> SeqHashSet<Region>
self.