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, maybe empty for anonymous adt (struct or union).
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
impl<'tcx> VariantDef
Sourcepub fn inhabited_predicate(
&self,
tcx: TyCtxt<'tcx>,
adt: AdtDef<'_>,
) -> InhabitedPredicate<'tcx>
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
impl VariantDef
Sourcepub fn new(
name: Symbol,
variant_did: Option<DefId>,
ctor: Option<(CtorKind, DefId)>,
discr: VariantDiscr,
fields: IndexVec<FieldIdx, FieldDef>,
adt_kind: AdtKind,
parent_did: DefId,
recover_tainted: Option<ErrorGuaranteed>,
is_field_list_non_exhaustive: bool,
) -> Self
pub fn new( name: Symbol, variant_did: Option<DefId>, ctor: Option<(CtorKind, DefId)>, discr: VariantDiscr, fields: IndexVec<FieldIdx, FieldDef>, adt_kind: AdtKind, 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.
Sourcepub fn is_field_list_non_exhaustive(&self) -> bool
pub fn is_field_list_non_exhaustive(&self) -> bool
Is this field list non-exhaustive?
Sourcepub fn ident(&self, tcx: TyCtxt<'_>) -> Ident
pub fn ident(&self, tcx: TyCtxt<'_>) -> Ident
Computes the Ident
of this variant by looking up the Span
Sourcepub fn has_errors(&self) -> Result<(), ErrorGuaranteed>
pub fn has_errors(&self) -> Result<(), ErrorGuaranteed>
Was this variant obtained as part of recovering from a syntactic error?
pub fn ctor_kind(&self) -> Option<CtorKind>
pub fn ctor_def_id(&self) -> Option<DefId>
Sourcepub fn single_field(&self) -> &FieldDef
pub fn single_field(&self) -> &FieldDef
Returns the one field in this variant.
panic!
s if there are no fields or multiple fields.
Sourcepub fn tail_opt(&self) -> Option<&FieldDef>
pub fn tail_opt(&self) -> Option<&FieldDef>
Returns the last field in this variant, if present.
Sourcepub fn has_unsafe_fields(&self) -> bool
pub fn has_unsafe_fields(&self) -> bool
Returns whether this variant has unsafe fields.
Trait Implementations§
Source§impl Debug for VariantDef
impl Debug for VariantDef
Source§impl<__D: TyDecoder> Decodable<__D> for VariantDef
impl<__D: TyDecoder> Decodable<__D> for VariantDef
Source§impl<__E: TyEncoder> Encodable<__E> for VariantDef
impl<__E: TyEncoder> Encodable<__E> for VariantDef
Source§impl Hash for VariantDef
impl Hash for VariantDef
Source§impl<'__ctx> HashStable<StableHashingContext<'__ctx>> for VariantDef
impl<'__ctx> HashStable<StableHashingContext<'__ctx>> for VariantDef
fn hash_stable( &self, __hcx: &mut StableHashingContext<'__ctx>, __hasher: &mut StableHasher, )
Source§impl PartialEq for VariantDef
impl PartialEq for VariantDef
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<Tcx, T> DepNodeParams<Tcx> for T
impl<Tcx, T> DepNodeParams<Tcx> for T
default fn fingerprint_style() -> FingerprintStyle
Source§default fn to_fingerprint(&self, tcx: Tcx) -> Fingerprint
default fn to_fingerprint(&self, tcx: Tcx) -> Fingerprint
default fn to_debug_str(&self, _: Tcx) -> String
Source§default fn recover(_: Tcx, _: &DepNode) -> Option<T>
default fn recover(_: Tcx, _: &DepNode) -> Option<T>
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
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Filterable for T
impl<T> Filterable for T
Source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<P> IntoQueryParam<P> for P
impl<P> IntoQueryParam<P> for P
fn into_query_param(self) -> P
Source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
Source§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> T
Source§impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed, ) -> T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> MaybeSendSync for T
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