[−][src]Enum rustc_mir_build::thir::pattern::_match::Constructor

pub(in thir::pattern::_match) enum Constructor<'tcx> {
    Single,
    Variant(DefId),
    IntRange(IntRange<'tcx>),
    FloatRange(&'tcx Const<'tcx>, &'tcx Const<'tcx>, RangeEnd),
    Str(&'tcx Const<'tcx>),
    Slice(Slice),
    Opaque,
    NonExhaustive,
    Wildcard,
}

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(DefId)

Enum variants.

IntRange(IntRange<'tcx>)

Ranges of integer literal values (2, 2..=5 or 2..5).

FloatRange(&'tcx Const<'tcx>, &'tcx Const<'tcx>, RangeEnd)

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.

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.

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.

Wildcard

Wildcard pattern.

Implementations

impl<'tcx> Constructor<'tcx>[src]

pub(in thir::pattern::_match) fn is_wildcard(
    &self
) -> bool
[src]

pub(in thir::pattern::_match) fn as_int_range(
    &self
) -> Option<&IntRange<'tcx>>
[src]

pub(in thir::pattern::_match) fn as_slice(
    &self
) -> Option<Slice>
[src]

pub(in thir::pattern::_match) fn variant_index_for_adt(
    &self,
    adt: &'tcx AdtDef
) -> VariantIdx
[src]

pub(in thir::pattern::_match) fn split<'p>(
    &self,
    pcx: PatCtxt<'_, 'p, 'tcx>,
    hir_id: Option<HirId>
) -> SmallVec<[Self; 1]>
[src]

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]

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]

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]

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]

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]

impl<'tcx> Debug for Constructor<'tcx>[src]

impl<'tcx> PartialEq<Constructor<'tcx>> for Constructor<'tcx>[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]

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

impl<'a, T> Captures<'a> for T where
    T: ?Sized, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone, 
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.