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 unions 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 DefIds.

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

Creates a new AdtDefData.

Trait Implementations

Immutably borrows from an owned value. Read more

There should be only one AdtDef for each did, therefore it is fine to implement Hash only based on did.

Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more

There should be only one AdtDef for each did, therefore it is fine to implement Ord only based on did.

This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more

There should be only one AdtDef for each did, therefore it is fine to implement PartialEq only based on did.

This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion 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: 56 bytes