Struct rustc_middle::ty::AdtDefData
source · pub struct AdtDefData {
pub did: DefId,
variants: IndexVec<VariantIdx, VariantDef>,
flags: AdtFlags,
repr: ReprOptions,
}
Expand description
The definition of a user-defined type, e.g., a struct
, enum
, or union
.
These are all interned (by alloc_adt_def
) into the global arena.
The initialism ADT stands for an algebraic data type (ADT).
This is slightly wrong because union
s are not ADTs.
Moreover, Rust only allows recursive data types through indirection.
Recursive types
It may seem impossible to represent recursive types using Ty
,
since TyKind::Adt
includes AdtDef
, which includes its fields,
creating a cycle. However, AdtDef
does not actually include the types
of its fields; it includes just their DefId
s.
For example, the following type:
struct S { x: Box<S> }
is essentially represented with Ty
as the following pseudocode:
struct S { x }
where x
here represents the DefId
of S.x
. Then, the DefId
can be used with TyCtxt::type_of()
to get the type of the field.
Fields
did: DefId
The DefId
of the struct, enum or union item.
variants: IndexVec<VariantIdx, VariantDef>
Variants of the ADT. If this is a struct or union, then there will be a single variant.
flags: AdtFlags
Flags of the ADT (e.g., is this a struct? is this non-exhaustive?).
repr: ReprOptions
Repr options provided by the user.
Implementations
sourceimpl AdtDefData
impl AdtDefData
sourcepub(super) fn new(
tcx: TyCtxt<'_>,
did: DefId,
kind: AdtKind,
variants: IndexVec<VariantIdx, VariantDef>,
repr: ReprOptions
) -> Self
pub(super) fn new(
tcx: TyCtxt<'_>,
did: DefId,
kind: AdtKind,
variants: IndexVec<VariantIdx, VariantDef>,
repr: ReprOptions
) -> Self
Creates a new AdtDefData
.
Trait Implementations
sourceimpl<'tcx> ArenaAllocatable<'tcx, IsNotCopy> for AdtDefData
impl<'tcx> ArenaAllocatable<'tcx, IsNotCopy> for AdtDefData
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self
fn allocate_from_iter<'a>(
arena: &'a Arena<'tcx>,
iter: impl IntoIterator<Item = Self>
) -> &'a mut [Self]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
sourceimpl<'tcx> Borrow<AdtDefData> for InternedInSet<'tcx, AdtDefData>
impl<'tcx> Borrow<AdtDefData> for InternedInSet<'tcx, AdtDefData>
sourcefn borrow<'a>(&'a self) -> &'a AdtDefData
fn borrow<'a>(&'a self) -> &'a AdtDefData
sourceimpl<'tcx, __D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<__D> for AdtDefData
impl<'tcx, __D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<__D> for AdtDefData
sourceimpl<'tcx, __E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<__E> for AdtDefData
impl<'tcx, __E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<__E> for AdtDefData
sourceimpl Hash for AdtDefData
impl Hash for AdtDefData
There should be only one AdtDef for each did
, therefore
it is fine to implement Hash
only based on did
.
sourceimpl<'a> HashStable<StableHashingContext<'a>> for AdtDefData
impl<'a> HashStable<StableHashingContext<'a>> for AdtDefData
fn hash_stable(
&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher
)
sourceimpl Ord for AdtDefData
impl Ord for AdtDefData
There should be only one AdtDef for each did
, therefore
it is fine to implement Ord
only based on did
.
sourcefn cmp(&self, other: &AdtDefData) -> Ordering
fn cmp(&self, other: &AdtDefData) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl PartialEq<AdtDefData> for AdtDefData
impl PartialEq<AdtDefData> for AdtDefData
There should be only one AdtDef for each did
, therefore
it is fine to implement PartialEq
only based on did
.
sourceimpl PartialOrd<AdtDefData> for AdtDefData
impl PartialOrd<AdtDefData> for AdtDefData
sourcefn partial_cmp(&self, other: &AdtDefData) -> Option<Ordering>
fn partial_cmp(&self, other: &AdtDefData) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresourceimpl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for AdtDefData
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for AdtDefData
impl Eq for AdtDefData
Auto Trait Implementations
impl RefUnwindSafe for AdtDefData
impl Send for AdtDefData
impl Sync for AdtDefData
impl Unpin for AdtDefData
impl UnwindSafe for AdtDefData
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
sourceimpl<T, R> InternIteratorElement<T, R> for T
impl<T, R> InternIteratorElement<T, R> for T
type Output = R
fn intern_with<I, F>(iter: I, f: F) -> <T as InternIteratorElement<T, R>>::Outputwhere
I: Iterator<Item = T>,
F: FnOnce(&[T]) -> R,
sourceimpl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
sourceimpl<CTX, T> Value<CTX> for Twhere
CTX: DepContext,
impl<CTX, T> Value<CTX> for Twhere
CTX: DepContext,
default fn from_cycle_error(tcx: CTX) -> T
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
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: 56 bytes