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) -> Selfwhere
Ty: TyAbiInterface<'a, C>,
pub fn field<C>(self, cx: &C, i: usize) -> Selfwhere
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) -> boolwhere
Ty: TyAbiInterface<'a, C>,
C: HasDataLayout,
pub fn is_adt<C>(self) -> boolwhere
Ty: TyAbiInterface<'a, C>,
pub fn is_never<C>(self) -> boolwhere
Ty: TyAbiInterface<'a, C>,
pub fn is_tuple<C>(self) -> boolwhere
Ty: TyAbiInterface<'a, C>,
pub fn is_unit<C>(self) -> boolwhere
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) -> boolwhere
Self: Copy,
Ty: TyAbiInterface<'a, C>,
C: HasDataLayout,
pub fn might_permit_raw_init<C>(self, cx: &C, init_kind: InitKind) -> boolwhere
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.
This code is intentionally conservative, and will not detect
- zero init of an enum whose 0 variant does not allow zero initialization
- making uninitialized types who have a full valid range (ints, floats, raw pointers)
- Any form of invalid value being made inside an array (unless the value is uninhabited)
A strict form of these checks that uses const evaluation exists in
rustc_const_eval::might_permit_raw_init
, and a tracking issue for making these checks
stricter is https://github.com/rust-lang/rust/issues/66151.
FIXME: Once all the conservatism is removed from here, and the checks are ran by default, we can use the const evaluation checks always instead.
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>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl<'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
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 Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
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.