Struct rustc_middle::ty::AdtDef [−][src]
pub struct AdtDef {
pub did: DefId,
pub variants: IndexVec<VariantIdx, VariantDef>,
flags: AdtFlags,
pub 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.
Fields
did: DefIdExpand description
The DefId of the struct, enum or union item.
variants: IndexVec<VariantIdx, VariantDef>Expand description
Variants of the ADT. If this is a struct or union, then there will be a single variant.
flags: AdtFlagsExpand description
Flags of the ADT (e.g., is this a struct? is this non-exhaustive?).
repr: ReprOptionsExpand description
Repr options provided by the user.
Implementations
impl<'tcx> AdtDef[src]
impl<'tcx> AdtDef[src]fn uninhabited_from(
&self,
tcx: TyCtxt<'tcx>,
substs: SubstsRef<'tcx>,
param_env: ParamEnv<'tcx>
) -> DefIdForest[src]
fn uninhabited_from(
&self,
tcx: TyCtxt<'tcx>,
substs: SubstsRef<'tcx>,
param_env: ParamEnv<'tcx>
) -> DefIdForest[src]Calculates the forest of DefIds from which this ADT is visibly uninhabited.
impl<'tcx> AdtDef[src]
impl<'tcx> AdtDef[src]pub(super) fn new(
tcx: TyCtxt<'_>,
did: DefId,
kind: AdtKind,
variants: IndexVec<VariantIdx, VariantDef>,
repr: ReprOptions
) -> Self[src]
pub(super) fn new(
tcx: TyCtxt<'_>,
did: DefId,
kind: AdtKind,
variants: IndexVec<VariantIdx, VariantDef>,
repr: ReprOptions
) -> Self[src]Creates a new AdtDef.
pub fn is_variant_list_non_exhaustive(&self) -> bool[src]
pub fn is_variant_list_non_exhaustive(&self) -> bool[src]Returns true if the variant list of this ADT is #[non_exhaustive].
pub fn variant_descr(&self) -> &'static str[src]
pub fn variant_descr(&self) -> &'static str[src]Returns a description of a variant of this abstract data type.
pub fn has_ctor(&self) -> bool[src]
pub fn has_ctor(&self) -> bool[src]If this function returns true, it implies that is_struct must return true.
pub fn is_fundamental(&self) -> bool[src]
pub fn is_fundamental(&self) -> bool[src]Returns true if this type is #[fundamental] for the purposes
of coherence checking.
pub fn is_phantom_data(&self) -> bool[src]
pub fn is_phantom_data(&self) -> bool[src]Returns true if this is PhantomData<T>.
pub fn is_manually_drop(&self) -> bool[src]
pub fn is_manually_drop(&self) -> bool[src]Returns true if this is ManuallyDrop<T>.
pub fn non_enum_variant(&self) -> &VariantDef[src]
pub fn non_enum_variant(&self) -> &VariantDef[src]Asserts this is a struct or union and returns its unique variant.
pub fn predicates(&self, tcx: TyCtxt<'tcx>) -> GenericPredicates<'tcx>[src]
pub fn all_fields(&self) -> impl Iterator<Item = &FieldDef> + Clone[src]
pub fn all_fields(&self) -> impl Iterator<Item = &FieldDef> + Clone[src]Returns an iterator over all fields contained by this ADT.
pub fn is_payloadfree(&self) -> bool[src]
pub fn is_payloadfree(&self) -> bool[src]Whether the ADT lacks fields. Note that this includes uninhabited enums,
e.g., enum Void {} is considered payload free as well.
pub fn variant_with_id(&self, vid: DefId) -> &VariantDef[src]
pub fn variant_with_id(&self, vid: DefId) -> &VariantDef[src]Return a VariantDef given a variant id.
pub fn variant_with_ctor_id(&self, cid: DefId) -> &VariantDef[src]
pub fn variant_with_ctor_id(&self, cid: DefId) -> &VariantDef[src]Return a VariantDef given a constructor id.
pub fn variant_index_with_id(&self, vid: DefId) -> VariantIdx[src]
pub fn variant_index_with_id(&self, vid: DefId) -> VariantIdx[src]Return the index of VariantDef given a variant id.
pub fn variant_index_with_ctor_id(&self, cid: DefId) -> VariantIdx[src]
pub fn variant_index_with_ctor_id(&self, cid: DefId) -> VariantIdx[src]Return the index of VariantDef given a constructor id.
pub fn variant_of_res(&self, res: Res) -> &VariantDef[src]
pub fn eval_explicit_discr(
&self,
tcx: TyCtxt<'tcx>,
expr_did: DefId
) -> Option<Discr<'tcx>>[src]
&self,
tcx: TyCtxt<'tcx>,
expr_did: DefId
) -> Option<Discr<'tcx>>
pub fn discriminants(
&'tcx self,
tcx: TyCtxt<'tcx>
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx>[src]
&'tcx self,
tcx: TyCtxt<'tcx>
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx>
pub fn variant_range(&self) -> Range<VariantIdx>[src]
pub fn discriminant_for_variant(
&self,
tcx: TyCtxt<'tcx>,
variant_index: VariantIdx
) -> Discr<'tcx>[src]
pub fn discriminant_for_variant(
&self,
tcx: TyCtxt<'tcx>,
variant_index: VariantIdx
) -> Discr<'tcx>[src]Computes the discriminant value used by a specific variant.
Unlike discriminants, this is (amortized) constant-time,
only doing at most one query for evaluating an explicit
discriminant (the last one before the requested variant),
assuming there are no constant-evaluation errors there.
pub fn discriminant_def_for_variant(
&self,
variant_index: VariantIdx
) -> (Option<DefId>, u32)[src]
pub fn discriminant_def_for_variant(
&self,
variant_index: VariantIdx
) -> (Option<DefId>, u32)[src]Yields a DefId for the discriminant and an offset to add to it
Alternatively, if there is no explicit discriminant, returns the
inferred discriminant directly.
pub fn destructor(&self, tcx: TyCtxt<'tcx>) -> Option<Destructor>[src]
pub fn sized_constraint(&self, tcx: TyCtxt<'tcx>) -> &'tcx [Ty<'tcx>]ⓘ[src]
pub fn sized_constraint(&self, tcx: TyCtxt<'tcx>) -> &'tcx [Ty<'tcx>]ⓘ[src]Returns a list of types such that Self: Sized if and only
if that type is Sized, or TyErr if this type is recursive.
Oddly enough, checking that the sized-constraint is Sized is
actually more expressive than checking all members:
the Sized trait is inductive, so an associated type that references
Self would prevent its containing ADT from being Sized.
Due to normalization being eager, this applies even if the associated type is behind a pointer (e.g., issue #31299).
Trait Implementations
impl<'tcx> ArenaAllocatable<'tcx, AdtDef> for AdtDef[src]
impl<'tcx> ArenaAllocatable<'tcx, AdtDef> for AdtDef[src]fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self[src]
fn allocate_from_iter<'a>(
arena: &'a Arena<'tcx>,
iter: impl IntoIterator<Item = Self>
) -> &'a mut [Self]ⓘ[src]
arena: &'a Arena<'tcx>,
iter: impl IntoIterator<Item = Self>
) -> &'a mut [Self]ⓘ
impl<'a> HashStable<StableHashingContext<'a>> for AdtDef[src]
impl<'a> HashStable<StableHashingContext<'a>> for AdtDef[src]fn hash_stable(
&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher
)[src]
&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher
)
impl Ord for AdtDef[src]
impl Ord for AdtDef[src]There should be only one AdtDef for each did, therefore
it is fine to implement Ord only based on did.
impl PartialOrd<AdtDef> for AdtDef[src]
impl PartialOrd<AdtDef> for AdtDef[src]fn partial_cmp(&self, other: &AdtDef) -> Option<Ordering>[src]
fn partial_cmp(&self, other: &AdtDef) -> Option<Ordering>[src]This method returns an ordering between self and other values if one exists. Read more
#[must_use]fn lt(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool1.0.0[src]This method tests less than (for self and other) and is used by the < operator. Read more
#[must_use]fn le(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool1.0.0[src]This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for AdtDef[src]
impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for AdtDef[src]impl<'tcx> TypeFoldable<'tcx> for &'tcx AdtDef[src]
impl<'tcx> TypeFoldable<'tcx> for &'tcx AdtDef[src]AdtDefs are basically the same as a DefId.
fn super_fold_with<F: TypeFolder<'tcx>>(self, _folder: &mut F) -> Self[src]
fn super_visit_with<V: TypeVisitor<'tcx>>(
&self,
_visitor: &mut V
) -> ControlFlow<V::BreakTy>[src]
&self,
_visitor: &mut V
) -> ControlFlow<V::BreakTy>
fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self[src]
fn visit_with<V: TypeVisitor<'tcx>>(
&self,
visitor: &mut V
) -> ControlFlow<V::BreakTy>[src]
&self,
visitor: &mut V
) -> ControlFlow<V::BreakTy>
fn has_vars_bound_at_or_above(&self, binder: DebruijnIndex) -> bool[src]
fn has_vars_bound_at_or_above(&self, binder: DebruijnIndex) -> bool[src]Returns true if self has any late-bound regions that are either
bound by binder or bound by some binder outside of binder.
If binder is ty::INNERMOST, this indicates whether
there are any late-bound regions that appear free. Read more
fn has_vars_bound_above(&self, binder: DebruijnIndex) -> bool[src]
fn has_vars_bound_above(&self, binder: DebruijnIndex) -> bool[src]Returns true if this self has any regions that escape binder (and
hence are not bound by it). Read more
fn has_escaping_bound_vars(&self) -> bool[src]
fn has_type_flags(&self, flags: TypeFlags) -> bool[src]
fn has_projections(&self) -> bool[src]
fn has_opaque_types(&self) -> bool[src]
fn references_error(&self) -> bool[src]
fn has_param_types_or_consts(&self) -> bool[src]
fn has_infer_regions(&self) -> bool[src]
fn has_infer_types(&self) -> bool[src]
fn has_infer_types_or_consts(&self) -> bool[src]
fn needs_infer(&self) -> bool[src]
fn has_placeholders(&self) -> bool[src]
fn needs_subst(&self) -> bool[src]
fn has_free_regions(&self) -> bool[src]
fn has_free_regions(&self) -> bool[src]“Free” regions in this context means that it has any region that is not (a) erased or (b) late-bound. Read more
fn has_erased_regions(&self) -> bool[src]
fn has_erasable_regions(&self) -> bool[src]
fn has_erasable_regions(&self) -> bool[src]True if there are any un-erased free regions.
fn is_global(&self) -> bool[src]
fn is_global(&self) -> bool[src]Indicates whether this value references only ‘global’ generic parameters that are the same regardless of what fn we are in. This is used for caching. Read more
fn has_late_bound_regions(&self) -> bool[src]
fn has_late_bound_regions(&self) -> bool[src]True if there are any late-bound regions
fn still_further_specializable(&self) -> bool[src]
fn still_further_specializable(&self) -> bool[src]Indicates whether this value still has parameters/placeholders/inference variables
which could be replaced later, in a way that would change the results of impl
specialization. Read more
impl Eq for AdtDef[src]
Auto Trait Implementations
impl RefUnwindSafe for AdtDef
impl !Send for AdtDef
impl !Sync for AdtDef
impl Unpin for AdtDef
impl UnwindSafe for AdtDef
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]pub fn borrow_mut(&mut self) -> &mut T[src]
pub fn borrow_mut(&mut self) -> &mut T[src]Mutably borrows from an owned value. Read more
impl<T> MaybeResult<T> for T[src]
impl<T> MaybeResult<T> for T[src]impl<T> WithConstness for T[src]
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, [src]
T: ?Sized,