Struct rustc_target::abi::TyAndLayout
source · [−]pub struct TyAndLayout<'a, Ty> {
pub ty: Ty,
pub layout: Layout<'a>,
}
Expand description
The layout of a type, alongside the type itself. Provides various type traversal APIs (e.g., recursing into fields).
Note that the layout is NOT guaranteed to always be identical
to that obtained from layout_of(ty)
, as we need to produce
layouts for which Rust types do not exist, such as enum variants
or synthetic fields of enums (i.e., discriminants) and fat pointers.
Fields
ty: Ty
layout: Layout<'a>
Implementations
sourceimpl<'a, Ty> TyAndLayout<'a, Ty>
impl<'a, Ty> TyAndLayout<'a, Ty>
fn is_aggregate(&self) -> bool
sourcepub fn homogeneous_aggregate<C>(
&self,
cx: &C
) -> Result<HomogeneousAggregate, Heterogeneous> where
Ty: TyAbiInterface<'a, C> + Copy,
pub fn homogeneous_aggregate<C>(
&self,
cx: &C
) -> Result<HomogeneousAggregate, Heterogeneous> where
Ty: TyAbiInterface<'a, C> + Copy,
Returns Homogeneous
if this layout is an aggregate containing fields of
only a single type (e.g., (u32, u32)
). Such aggregates are often
special-cased in ABIs.
Note: We generally ignore fields of zero-sized type when computing this value (see #56877).
This is public so that it can be used in unit tests, but should generally only be relevant to the ABI details of specific targets.
sourceimpl<'a, Ty> TyAndLayout<'a, Ty>
impl<'a, Ty> TyAndLayout<'a, Ty>
pub fn for_variant<C>(self, cx: &C, variant_index: VariantIdx) -> Self where
Ty: TyAbiInterface<'a, C>,
pub fn field<C>(self, cx: &C, i: usize) -> Self where
Ty: TyAbiInterface<'a, C>,
pub fn pointee_info_at<C>(self, cx: &C, offset: Size) -> Option<PointeeInfo> where
Ty: TyAbiInterface<'a, C>,
pub fn is_single_fp_element<C>(self, cx: &C) -> bool where
Ty: TyAbiInterface<'a, C>,
C: HasDataLayout,
pub fn is_adt<C>(self) -> bool where
Ty: TyAbiInterface<'a, C>,
pub fn is_never<C>(self) -> bool where
Ty: TyAbiInterface<'a, C>,
pub fn is_tuple<C>(self) -> bool where
Ty: TyAbiInterface<'a, C>,
pub fn is_unit<C>(self) -> bool where
Ty: TyAbiInterface<'a, C>,
sourceimpl<'a, Ty> TyAndLayout<'a, Ty>
impl<'a, Ty> TyAndLayout<'a, Ty>
sourcepub fn is_unsized(&self) -> bool
pub fn is_unsized(&self) -> bool
Returns true
if the layout corresponds to an unsized type.
sourcepub fn might_permit_raw_init<C>(
self,
cx: &C,
init_kind: InitKind,
strict: bool
) -> bool where
Self: Copy,
Ty: TyAbiInterface<'a, C>,
C: HasDataLayout,
pub fn might_permit_raw_init<C>(
self,
cx: &C,
init_kind: InitKind,
strict: bool
) -> bool where
Self: Copy,
Ty: TyAbiInterface<'a, C>,
C: HasDataLayout,
Determines if this type permits “raw” initialization by just transmuting some
memory into an instance of T
.
init_kind
indicates if the memory is zero-initialized or left uninitialized.
strict
is an opt-in debugging flag added in #97323 that enables more checks.
This is conservative: in doubt, it will answer true
.
FIXME: Once we removed all the conservatism, we could alternatively create an all-0/all-undef constant and run the const value validator to see if this is a valid value for the given type.
Trait Implementations
sourceimpl<'a, Ty: Clone> Clone for TyAndLayout<'a, Ty>
impl<'a, Ty: Clone> Clone for TyAndLayout<'a, Ty>
sourcefn clone(&self) -> TyAndLayout<'a, Ty>
fn clone(&self) -> TyAndLayout<'a, Ty>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'a, Ty: Debug> Debug for TyAndLayout<'a, Ty>
impl<'a, Ty: Debug> Debug for TyAndLayout<'a, Ty>
sourceimpl<'a, Ty> Deref for TyAndLayout<'a, Ty>
impl<'a, Ty> Deref for TyAndLayout<'a, Ty>
sourceimpl<'a, Ty: Hash> Hash for TyAndLayout<'a, Ty>
impl<'a, Ty: Hash> Hash for TyAndLayout<'a, Ty>
sourceimpl<'a, Ty, __CTX> HashStable<__CTX> for TyAndLayout<'a, Ty> where
__CTX: HashStableContext,
Ty: HashStable<__CTX>,
impl<'a, Ty, __CTX> HashStable<__CTX> for TyAndLayout<'a, Ty> where
__CTX: HashStableContext,
Ty: HashStable<__CTX>,
fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)
sourceimpl<'a, Ty: PartialEq> PartialEq<TyAndLayout<'a, Ty>> for TyAndLayout<'a, Ty>
impl<'a, Ty: PartialEq> PartialEq<TyAndLayout<'a, Ty>> for TyAndLayout<'a, Ty>
sourcefn eq(&self, other: &TyAndLayout<'a, Ty>) -> bool
fn eq(&self, other: &TyAndLayout<'a, Ty>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &TyAndLayout<'a, Ty>) -> bool
fn ne(&self, other: &TyAndLayout<'a, Ty>) -> bool
This method tests for !=
.
impl<'a, Ty: Copy> Copy for TyAndLayout<'a, Ty>
impl<'a, Ty: Eq> Eq for TyAndLayout<'a, Ty>
impl<'a, Ty> StructuralEq for TyAndLayout<'a, Ty>
impl<'a, Ty> StructuralPartialEq for TyAndLayout<'a, Ty>
Auto Trait Implementations
impl<'a, Ty> RefUnwindSafe for TyAndLayout<'a, Ty> where
Ty: RefUnwindSafe,
impl<'a, Ty> Send for TyAndLayout<'a, Ty> where
Ty: Send,
impl<'a, Ty> Sync for TyAndLayout<'a, Ty> where
Ty: Sync,
impl<'a, Ty> Unpin for TyAndLayout<'a, Ty> where
Ty: Unpin,
impl<'a, Ty> UnwindSafe for TyAndLayout<'a, Ty> where
Ty: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Layout
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.