Skip to main content

TermPatternKind

Enum TermPatternKind 

Source
pub enum TermPatternKind {
    Anything,
    Bind(String),
    Literal {
        tpe: Type,
        value: LiteralValue,
    },
    Constructor {
        ctor: Constructor,
        adt_args: Vec<Type>,
        args: Vec<SubPattern>,
    },
    Tuple {
        elements: Tuple<SubPattern>,
    },
    Unit,
    Hole {
        args: Vec<SubPattern>,
    },
    Record {
        fields: Vec<Field<SubPattern>>,
    },
}

Variants§

§

Anything

Matches anything without binding.

§

Bind(String)

Binds the scrutinee type to this name.

§

Literal

Matches one specific value; constrains the scrutinee to the type carried here and, unlike the type alone, says which value of it.

tpe is a Type::Literal for an Int, Float, Char or String pattern, and the Type::Adt typer::bool_type builds for a Basics.True/Basics.False one — Bool is the union Basics declares, not a literal type. Two patterns of that same kind — two Ints, say — share that one type, so value is what tells 1 from 2, or True from False; decision_tree reads it to build the Outcome a Decision::Test checks for.

Fields

§tpe: Type
§

Constructor

Matches an ADT constructor; carries the fresh ADT args and one sub-pattern per argument.

Fields

§ctor: Constructor

Which constructor, and where it sits in its declaration. ctor.union is the name the Type::Adt this pattern constrains the scrutinee to is built from.

§adt_args: Vec<Type>
§args: Vec<SubPattern>

One per argument the pattern writes, in order, so an argument’s place in this Vec is its position in the constructor.

§

Tuple

Matches a tuple of two or three elements; carries one sub-pattern per element.

Fields

§elements: Tuple<SubPattern>

One per element, in order. The matched value’s tuple type is built from their types.

§

Unit

Matches the one value of the unit type: constrains the matched value to Type::Unit and binds nothing. Since that type has a single value, decision_tree builds no test for it.

§

Hole

A constructor pattern whose constructor did not resolve, translated from canonical::PatternKind::Hole; carries one sub-pattern per argument written after it, each at a fresh type.

It places no constraint on the matched value, since nothing says what type the constructor would have built, and binds what its arguments bind, as a constructor’s do. decision_tree tests nothing for it, as for Anything, and no backend emits a tree built from one.

Fields

§

Record

A record pattern: one entry per label it writes, in the order written, each the label, where the label alone was written, and the sub-pattern that field’s value is matched against, at the field’s type. The { label } shorthand arrives here as label = label.

It names a subset of the record’s fields, so no record type is built from its entries: the type of the value it is matched against comes from elsewhere in the declaration, and each entry is read against it once it is known (typer::FieldConstraint). A record has one shape, so decision_tree tests nothing for the pattern itself and goes on to each entry by a Step::Field. It is refutable exactly when one of its entries is, and nothing reads it as irrefutable for being a record.

Fields

Trait Implementations§

Source§

impl Clone for TermPatternKind

Source§

fn clone(&self) -> TermPatternKind

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TermPatternKind

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

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>,

Source§

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.