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.
Constructor
Matches an ADT constructor; carries the fresh ADT args and one sub-pattern per argument.
Fields
ctor: ConstructorWhich 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.
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
args: Vec<SubPattern>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
fields: Vec<Field<SubPattern>>Trait Implementations§
Source§impl Clone for TermPatternKind
impl Clone for TermPatternKind
Source§fn clone(&self) -> TermPatternKind
fn clone(&self) -> TermPatternKind
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more