Struct rustc_middle::ty::VariantDef[][src]

pub struct VariantDef {
    pub def_id: DefId,
    pub ctor_def_id: Option<DefId>,
    pub ident: Ident,
    pub discr: VariantDiscr,
    pub fields: Vec<FieldDef>,
    pub ctor_kind: CtorKind,
    flags: VariantFlags,

Definition of a variant – a struct’s fields or a enum variant.


def_id: DefId

DefId that identifies the variant itself. If this variant belongs to a struct or union, then this is a copy of its DefId.

ctor_def_id: Option<DefId>

DefId that identifies the variant’s constructor. If this variant is a struct variant, then this is None.

ident: Ident

Variant or struct name.

discr: VariantDiscr

Discriminant of this variant.

fields: Vec<FieldDef>

Fields of this variant.

ctor_kind: CtorKind

Type of constructor of variant.

flags: VariantFlags

Flags of the variant (e.g. is field list non-exhaustive)?


impl<'tcx> VariantDef[src]

pub fn uninhabited_from(
    tcx: TyCtxt<'tcx>,
    substs: SubstsRef<'tcx>,
    adt_kind: AdtKind,
    param_env: ParamEnv<'tcx>
) -> DefIdForest

Calculates the forest of DefIds from which this variant is visibly uninhabited.

impl VariantDef[src]

pub fn new(
    ident: Ident,
    variant_did: Option<DefId>,
    ctor_def_id: Option<DefId>,
    discr: VariantDiscr,
    fields: Vec<FieldDef>,
    ctor_kind: CtorKind,
    adt_kind: AdtKind,
    parent_did: DefId,
    recovered: bool,
    is_field_list_non_exhaustive: bool
) -> Self

Creates a new VariantDef.

variant_did is the DefId that identifies the enum variant (if this VariantDef represents an enum variant).

ctor_did is the DefId that identifies the constructor of unit or tuple-variants/structs. If this is a struct-variant then this should be None.

parent_did is the DefId of the AdtDef representing the enum or struct that owns this variant. It is used for checking if a struct has #[non_exhaustive] w/out having to go through the redirect of checking the ctor’s attributes - but compiling a small crate requires loading the AdtDefs for all the structs in the universe (e.g., coherence for any built-in trait), and we do not want to load attributes twice.

If someone speeds up attribute loading to not be a performance concern, they can remove this hack and use the constructor DefId everywhere.

pub fn is_field_list_non_exhaustive(&self) -> bool[src]

Is this field list non-exhaustive?

pub fn is_recovered(&self) -> bool[src]

Was this variant obtained as part of recovering from a syntactic error?

Trait Implementations

impl Debug for VariantDef[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<'__ctx> HashStable<StableHashingContext<'__ctx>> for VariantDef[src]

fn hash_stable(
    __hcx: &mut StableHashingContext<'__ctx>,
    __hasher: &mut StableHasher

Auto Trait Implementations

impl RefUnwindSafe for VariantDef

impl !Send for VariantDef

impl !Sync for VariantDef

impl Unpin for VariantDef

impl UnwindSafe for VariantDef

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> MaybeResult<T> for T[src]

type Error = !

pub fn from(Result<T, <T as MaybeResult<T>>::Error>) -> T[src]

pub fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<T> WithConstness for T[src]

fn with_constness(self, constness: Constness) -> ConstnessAnd<Self>[src]

fn with_const(self) -> ConstnessAnd<Self>[src]

fn without_const(self) -> ConstnessAnd<Self>[src]

impl<'a, T> Captures<'a> for T where
    T: ?Sized