pub enum Constructor<'tcx> {
Show 14 variants Single, Variant(VariantIdx), Bool(bool), IntRange(IntRange), F32Range(IeeeFloat<SingleS>, IeeeFloat<SingleS>, RangeEnd), F64Range(IeeeFloat<DoubleS>, IeeeFloat<DoubleS>, RangeEnd), Str(Const<'tcx>), Slice(Slice), Opaque(OpaqueId), Or, Wildcard, NonExhaustive, Hidden, Missing,
}
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 references. Fixed-length arrays are treated separately with Slice.

§

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

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. Carries an id that must be unique within a match. We need this to ensure the invariants of SplitConstructorSet.

§

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 at the top of the file.

Implementations§

source§

impl<'tcx> Constructor<'tcx>

source

pub(crate) fn is_non_exhaustive(&self) -> bool

source

pub(crate) fn as_variant(&self) -> Option<VariantIdx>

source

fn as_bool(&self) -> Option<bool>

source

pub(crate) fn as_int_range(&self) -> Option<&IntRange>

source

fn as_slice(&self) -> Option<Slice>

source

pub(crate) fn arity(&self, pcx: &PatCtxt<'_, '_, 'tcx>) -> usize

The number of fields for this constructor. This must be kept in sync with Fields::wildcards.

source

pub(crate) 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>

source§

fn clone(&self) -> Constructor<'tcx>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'tcx> Debug for Constructor<'tcx>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'tcx> PartialEq for Constructor<'tcx>

source§

fn eq(&self, other: &Constructor<'tcx>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

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 bytes
  • Variant: 7 bytes
  • Bool: 1 byte
  • IntRange: 55 bytes
  • F32Range: 55 bytes
  • F64Range: 55 bytes
  • Str: 47 bytes
  • Slice: 47 bytes
  • Opaque: 7 bytes
  • Or: 0 bytes
  • Wildcard: 0 bytes
  • NonExhaustive: 0 bytes
  • Hidden: 0 bytes
  • Missing: 0 bytes