## VariantDef

# Struct VariantDef

Source

    pub struct VariantDef {
        pub def_id: DefId,
        pub ctor: Option<(CtorKind, DefId)>,
        pub name: Symbol,
        pub discr: VariantDiscr,
        pub fields: IndexVec<FieldIdx, FieldDef>,
        tainted: Option<ErrorGuaranteed>,
        flags: VariantFlags,
    }

Expand description

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

## Fields§

§`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: Option<(CtorKind, DefId)>`

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

§`name: Symbol`

Variant or struct name.

§`discr: VariantDiscr`

Discriminant of this variant.

§`fields: IndexVec<FieldIdx, FieldDef>`

Fields of this variant.

§`tainted: Option<ErrorGuaranteed>`

The error guarantees from parser, if any.

§`flags: VariantFlags`

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

## Implementations§

Source§

### impl<'tcx> VariantDef

Source

#### pub fn inhabited_predicate( &self, tcx: TyCtxt<'tcx>, adt: AdtDef<'_>, ) -> InhabitedPredicate<'tcx>

Calculates the forest of `DefId`s from which this variant is visibly uninhabited.

Source§

### impl VariantDef

Source

#### pub fn new( name: Symbol, variant_did: Option<DefId>, ctor: Option<(CtorKind, DefId)>, discr: VariantDiscr, fields: IndexVec<FieldIdx, FieldDef>, parent_did: DefId, recover_tainted: Option<ErrorGuaranteed>, 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 `AdtDef`s 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.

Source

#### pub fn is_field_list_non_exhaustive(&self) -> bool

Returns `true` if the field list of this variant is `#[non_exhaustive]`.

Note that this function will return `true` even if the type has been defined in the crate currently being compiled. If that’s not what you want, see `Self::field_list_has_applicable_non_exhaustive`.

Source

#### pub fn field_list_has_applicable_non_exhaustive(&self) -> bool

Returns `true` if the field list of this variant is `#[non_exhaustive]` and the type has been defined in another crate.

Source

#### pub fn ident(&self, tcx: TyCtxt<'_>) -> Ident

Computes the `Ident` of this variant by looking up the `Span`

Source

#### pub fn has_errors(&self) -> Result<(), ErrorGuaranteed>

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

Source

#### pub fn ctor_kind(&self) -> Option<CtorKind>

Source

#### pub fn ctor_def_id(&self) -> Option<DefId>

Source

#### pub fn single_field(&self) -> &FieldDef

Returns the one field in this variant.

`panic!`s if there are no fields or multiple fields.

Source

#### pub fn tail_opt(&self) -> Option<&FieldDef>

Returns the last field in this variant, if present.

Source

#### pub fn tail(&self) -> &FieldDef

Returns the last field in this variant.

##### §Panics

Panics, if the variant has no fields.

Source

#### pub fn has_unsafe_fields(&self) -> bool

Returns whether this variant has unsafe fields.

## Trait Implementations§

Source§

### impl Debug for VariantDef

Source§

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

Formats the value using the given formatter. Read more
Source§

### impl<'tcx, __D: TyDecoder<'tcx>> Decodable<__D> for VariantDef

Source§

#### fn decode(__decoder: &mut __D) -> Self

Source§

### impl<'tcx, __E: TyEncoder<'tcx>> Encodable<__E> for VariantDef

Source§

#### fn encode(&self, __encoder: &mut __E)

Source§

### impl Hash for VariantDef

Source§

#### fn hash<H: Hasher>(&self, s: &mut H)

Feeds this value into the given `Hasher`. Read more
1.3.0 · Source§

#### fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given `Hasher`. Read more
Source§

### impl<'__ctx> HashStable<StableHashingContext<'__ctx>> for VariantDef

Source§

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

Source§

### impl PartialEq for VariantDef

Source§

#### fn eq(&self, other: &Self) -> bool

Tests for `self` and `other` values to be equal, and is used by `==`.
1.0.0 · Source§

#### fn ne(&self, other: &Rhs) -> bool

Tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

### impl Eq for VariantDef

## Auto Trait Implementations§

§

### impl DynSend for VariantDef

§

### impl DynSync for VariantDef

§

### impl Freeze for VariantDef

§

### impl RefUnwindSafe for VariantDef

§

### impl Send for VariantDef

§

### impl Sync for VariantDef

§

### impl Unpin for VariantDef

§

### impl UnwindSafe for VariantDef

## Blanket Implementations§

Source§

### impl<T> Aligned for T

Source§

#### const ALIGN: Alignment

Alignment of `Self`.
Source§

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

Source§

#### fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more
Source§

### impl<T> AnyEq for T
where T: Any + PartialEq,

Source§

#### fn equals(&self, other: &(dyn Any + 'static)) -> bool

Source§

#### fn as_any(&self) -> &(dyn Any + 'static)

Source§

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

Source§

#### fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

#### fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

### impl<T, R> CollectAndApply<T, R> for T

Source§

#### fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to `f(&iter.collect::<Vec<_>>())`.

Source§

#### type Output = R

Source§

### impl<Tcx, T> DepNodeParams<Tcx> for T
where Tcx: DepContext, T: for<'a> HashStable<StableHashingContext<'a>> + Debug,

Source§

#### default fn fingerprint_style() -> FingerprintStyle

Source§

#### default fn to_fingerprint(&self, tcx: Tcx) -> Fingerprint

This method turns the parameters of a DepNodeConstructor into an opaque Fingerprint to be used in DepNode. Not all DepNodeParams support being turned into a Fingerprint (they don’t need to if the corresponding DepNode is anonymous).
Source§

#### default fn to_debug_str(&self, tcx: Tcx) -> String

Source§

#### default fn recover(_: Tcx, _: &DepNode) -> Option<T>

This method tries to recover the query key from the given `DepNode`, something which is needed when forcing `DepNode`s during red-green evaluation. The query system will only call this method if `fingerprint_style()` is not `FingerprintStyle::Opaque`. It is always valid to return `None` here, in which case incremental compilation will treat the query as having changed instead of forcing it.
Source§

### impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

#### fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

### impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

#### fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

### impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

#### fn equivalent(&self, key: &K) -> bool

Compare self to `key` and return `true` if they are equal.
Source§

### impl<T> From<T> for T

Source§

#### fn from(t: T) -> T

Returns the argument unchanged.

Source§

### impl<T> Instrument for T

Source§

#### fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided `Span`, returning an `Instrumented` wrapper. Read more
Source§

#### fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current `Span`, returning an `Instrumented` wrapper. Read more
Source§

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

Source§

#### fn into(self) -> U

Calls `U::from(self)`.

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

Source§

### impl<T> IntoEither for T

Source§

#### fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts `self` into a `Left` variant of `Either<Self, Self>` if `into_left` is `true`. Converts `self` into a `Right` variant of `Either<Self, Self>` otherwise. Read more
Source§

#### fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts `self` into a `Left` variant of `Either<Self, Self>` if `into_left(&self)` returns `true`. Converts `self` into a `Right` variant of `Either<Self, Self>` otherwise. Read more
Source§

### impl<P> IntoQueryParam<P> for P

Source§

#### fn into_query_param(self) -> P

Source§

### impl<T> MaybeResult<T> for T

Source§

#### type Error = !

Source§

#### fn from(_: Result<T, <T as MaybeResult<T>>::Error>) -> T

Source§

#### fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>

Source§

### impl<T> Pointable for T

Source§

#### const ALIGN: usize

The alignment of pointer.
Source§

#### type Init = T

The type for initializers.
Source§

#### unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

#### unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

#### unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

#### unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

### impl<T> Same for T

Source§

#### type Output = T

Should always be `Self`
Source§

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

Source§

#### type Error = Infallible

The type returned in the event of a conversion error.
Source§

#### fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

#### fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

### impl<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

Source§

#### fn upcast(self, interner: I) -> U

Source§

### impl<I, T> UpcastFrom<I, T> for T

Source§

#### fn upcast_from(from: T, _tcx: I) -> T

Source§

### impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

#### fn vzip(self) -> V

Source§

### impl<Tcx, T> Value<Tcx> for T
where Tcx: DepContext,

Source§

#### default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed, ) -> T

Source§

### impl<T> WithSubscriber for T

Source§

#### fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided `Subscriber` to this type, returning a `WithDispatch` wrapper. Read more
Source§

#### fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default `Subscriber` to this type, returning a `WithDispatch` wrapper. Read more
Source§

### impl<T> ErasedDestructor for T
where T: 'static,

## 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: 64 bytes