[−][src]Enum rustc_mir_build::thir::pattern::_match::Constructor
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
The constructor for patterns that have a single constructor, like tuples, struct patterns and fixed-length arrays.
Variant(DefId)Enum variants.
IntRange(IntRange<'tcx>)Ranges of integer literal values (2, 2..=5 or 2..5).
Ranges of floating-point literal values (2.0..=5.2).
Str(&'tcx Const<'tcx>)String literals. Strings are not quite the same as &[u8] so we treat them separately.
Slice(Slice)Array and slice patterns.
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.
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.
Wildcard pattern.
Implementations
impl<'tcx> Constructor<'tcx>[src]
pub(in thir::pattern::_match) fn is_wildcard(
&self
) -> bool[src]
&self
) -> bool
pub(in thir::pattern::_match) fn as_int_range(
&self
) -> Option<&IntRange<'tcx>>[src]
&self
) -> Option<&IntRange<'tcx>>
pub(in thir::pattern::_match) fn as_slice(
&self
) -> Option<Slice>[src]
&self
) -> Option<Slice>
pub(in thir::pattern::_match) fn variant_index_for_adt(
&self,
adt: &'tcx AdtDef
) -> VariantIdx[src]
&self,
adt: &'tcx AdtDef
) -> VariantIdx
pub(in thir::pattern::_match) fn split<'p>(
&self,
pcx: PatCtxt<'_, 'p, 'tcx>,
hir_id: Option<HirId>
) -> SmallVec<[Self; 1]>[src]
&self,
pcx: PatCtxt<'_, 'p, 'tcx>,
hir_id: Option<HirId>
) -> SmallVec<[Self; 1]>
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 wrt 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 and
diagnostics. Eg. for the _ case, we ignore the constructors already present in the
matrix, unless all of them are.
hir_id is None when we're evaluating the wildcard pattern. In that case we do not want
to lint for overlapping ranges.
pub(in thir::pattern::_match) fn split_wildcard<'p>(
pcx: PatCtxt<'_, 'p, 'tcx>
) -> SmallVec<[Self; 1]>[src]
pcx: PatCtxt<'_, 'p, 'tcx>
) -> SmallVec<[Self; 1]>
For wildcards, there are two groups of constructors: there are the constructors actually
present in the matrix (head_ctors), and the constructors not present (missing_ctors).
Two constructors that are not in the matrix will either both be caught (by a wildcard), or
both not be caught. Therefore we can keep the missing constructors grouped together.
pub(in thir::pattern::_match) fn is_covered_by<'p>(
&self,
pcx: PatCtxt<'_, 'p, 'tcx>,
other: &Self
) -> bool[src]
&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.
pub(in thir::pattern::_match) fn is_covered_by_any<'p>(
&self,
pcx: PatCtxt<'_, 'p, 'tcx>,
used_ctors: &[Constructor<'tcx>]
) -> bool[src]
&self,
pcx: PatCtxt<'_, 'p, 'tcx>,
used_ctors: &[Constructor<'tcx>]
) -> bool
Faster version of is_covered_by when applied to many constructors. used_ctors is
assumed to be built from matrix.head_ctors() with wildcards filtered out, and self is
assumed to have been split from a wildcard.
pub(in thir::pattern::_match) fn apply<'p>(
&self,
pcx: PatCtxt<'_, 'p, 'tcx>,
fields: Fields<'p, 'tcx>
) -> Pat<'tcx>[src]
&self,
pcx: PatCtxt<'_, 'p, 'tcx>,
fields: Fields<'p, 'tcx>
) -> Pat<'tcx>
Apply a constructor to a list of patterns, yielding a new pattern. pats
must have as many elements as this constructor's arity.
This is roughly the inverse of specialize_constructor.
Examples:
self: Constructor::Single
ty: (u32, u32, u32)
pats: [10, 20, _]
returns (10, 20, _)
self: Constructor::Variant(Option::Some)
ty: Option<bool>
pats: [false]
returns Some(false)
Trait Implementations
impl<'tcx> Clone for Constructor<'tcx>[src]
pub fn clone(&self) -> Constructor<'tcx>[src]
pub fn clone_from(&mut self, source: &Self)1.0.0[src]
impl<'tcx> Debug for Constructor<'tcx>[src]
impl<'tcx> PartialEq<Constructor<'tcx>> for Constructor<'tcx>[src]
pub fn eq(&self, other: &Constructor<'tcx>) -> bool[src]
pub fn ne(&self, other: &Constructor<'tcx>) -> bool[src]
impl<'tcx> StructuralPartialEq for Constructor<'tcx>[src]
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
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<'a, T> Captures<'a> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
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]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,