Enum rustc_mir_build::thir::pattern::deconstruct_pat::Constructor
source · pub(super) enum Constructor<'tcx> {
}Expand description
A value can be decomposed into a constructor applied to some fields. This struct represents
the constructor. See also Fields.
pat_constructor retrieves the constructor corresponding to a pattern.
specialize_constructor returns the list of fields corresponding to a pattern, given a
constructor. Constructor::apply reconstructs the pattern from a pair of Constructor and
Fields.
Variants§
Single
The constructor for patterns that have a single constructor, like tuples, struct patterns and fixed-length arrays.
Variant(VariantIdx)
Enum variants.
Bool(bool)
Booleans
IntRange(IntRange)
Ranges of integer literal values (2, 2..=5 or 2..5).
F32Range(IeeeFloat<SingleS>, IeeeFloat<SingleS>, RangeEnd)
Ranges of floating-point literal values (2.0..=5.2).
F64Range(IeeeFloat<DoubleS>, IeeeFloat<DoubleS>, RangeEnd)
Str(Const<'tcx>)
String literals. Strings are not quite the same as &[u8] so we treat them separately.
Slice(Slice)
Array and slice patterns.
Opaque
Constants that must not be matched structurally. They are treated as black boxes for the purposes of exhaustiveness: we must not inspect them, and they don’t count towards making a match exhaustive.
Or
Or-pattern.
Wildcard
Wildcard pattern.
NonExhaustive
Fake extra constructor for enums that aren’t allowed to be matched exhaustively. Also used
for those types for which we cannot list constructors explicitly, like f64 and str.
Hidden
Fake extra constructor for variants that should not be mentioned in diagnostics.
We use this for variants behind an unstable gate as well as
#[doc(hidden)] ones.
Missing
Fake extra constructor for constructors that are not seen in the matrix, as explained in the
code for Constructor::split.
Implementations§
source§impl<'tcx> Constructor<'tcx>
impl<'tcx> Constructor<'tcx>
pub(super) fn is_non_exhaustive(&self) -> bool
pub(super) fn as_variant(&self) -> Option<VariantIdx>
fn as_bool(&self) -> Option<bool>
pub(super) fn as_int_range(&self) -> Option<&IntRange>
fn as_slice(&self) -> Option<Slice>
fn variant_index_for_adt(&self, adt: AdtDef<'tcx>) -> VariantIdx
sourcepub(super) fn arity(&self, pcx: &PatCtxt<'_, '_, 'tcx>) -> usize
pub(super) fn arity(&self, pcx: &PatCtxt<'_, '_, 'tcx>) -> usize
The number of fields for this constructor. This must be kept in sync with
Fields::wildcards.
sourcepub(super) fn split<'a>(
&self,
pcx: &PatCtxt<'_, '_, 'tcx>,
ctors: impl Iterator<Item = &'a Constructor<'tcx>> + Clone
) -> SmallVec<[Self; 1]>where
'tcx: 'a,
pub(super) fn split<'a>( &self, pcx: &PatCtxt<'_, '_, 'tcx>, ctors: impl Iterator<Item = &'a Constructor<'tcx>> + Clone ) -> SmallVec<[Self; 1]>where 'tcx: 'a,
Some constructors (namely Wildcard, IntRange and Slice) actually stand for a set of
actual constructors (like variants, integers or fixed-sized slices). When specializing for
these constructors, we want to be specialising for the actual underlying constructors.
Naively, we would simply return the list of constructors they correspond to. We instead are
more clever: if there are constructors that we know will behave the same w.r.t. the current
matrix, we keep them grouped. For example, all slices of a sufficiently large length will
either be all useful or all non-useful with a given matrix.
See the branches for details on how the splitting is done.
This function may discard some irrelevant constructors if this preserves behavior. Eg. for
the _ case, we ignore the constructors already present in the column, unless all of them
are.
sourcepub(super) fn is_covered_by<'p>(
&self,
pcx: &PatCtxt<'_, 'p, 'tcx>,
other: &Self
) -> bool
pub(super) fn is_covered_by<'p>( &self, pcx: &PatCtxt<'_, 'p, 'tcx>, other: &Self ) -> bool
Returns whether self is covered by other, i.e. whether self is a subset of other.
For the simple cases, this is simply checking for equality. For the “grouped” constructors,
this checks for inclusion.
Trait Implementations§
source§impl<'tcx> Clone for Constructor<'tcx>
impl<'tcx> Clone for Constructor<'tcx>
source§fn clone(&self) -> Constructor<'tcx>
fn clone(&self) -> Constructor<'tcx>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<'tcx> Debug for Constructor<'tcx>
impl<'tcx> Debug for Constructor<'tcx>
source§impl<'tcx> PartialEq for Constructor<'tcx>
impl<'tcx> PartialEq for Constructor<'tcx>
source§fn eq(&self, other: &Constructor<'tcx>) -> bool
fn eq(&self, other: &Constructor<'tcx>) -> bool
self and other values to be equal, and is used
by ==.impl<'tcx> StructuralPartialEq for Constructor<'tcx>
Auto Trait Implementations§
impl<'tcx> !RefUnwindSafe for Constructor<'tcx>
impl<'tcx> Send for Constructor<'tcx>
impl<'tcx> Sync for Constructor<'tcx>
impl<'tcx> Unpin for Constructor<'tcx>
impl<'tcx> !UnwindSafe for Constructor<'tcx>
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
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
Size for each variant:
Single: 0 bytesVariant: 7 bytesBool: 1 byteIntRange: 55 bytesF32Range: 55 bytesF64Range: 55 bytesStr: 47 bytesSlice: 47 bytesOpaque: 0 bytesOr: 0 bytesWildcard: 0 bytesNonExhaustive: 0 bytesHidden: 0 bytesMissing: 0 bytes