pub enum PatternKind {
Anything,
Variable(Name),
Int(i64),
Float(f64),
Char(char),
String(String),
Tuple(Tuple<Pattern>),
Unit,
Constructor {
ctor: TypeConstructor,
args: Vec<Pattern>,
},
Hole(Vec<Pattern>),
Record(Vec<PatternField>),
}Variants§
Anything
Variable(Name)
Int(i64)
Float(f64)
Char(char)
String(String)
Tuple(Tuple<Pattern>)
A tuple pattern. Zelkova keeps Elm’s restriction of two or three
elements, which [Tuple] carries in its shape.
Unit
The unit pattern, (): it matches the one value of the unit type and binds
nothing.
Constructor
Hole(Vec<Pattern>)
A constructor pattern whose constructor did not resolve, with the patterns written
as its arguments. The error saying so has been reported, or dropped in an
incomplete scope, and the declaration is kept (DEC-23
decision
6).
The arguments are kept so that the names they bind are still in scope in the branch or the body the pattern governs, and a use of one there is not reported as a second missing name.
Record(Vec<PatternField>)
A record pattern, { label = pattern, … }: the fields it names, each with the pattern its value is matched
against, in the order they were written. The { label } shorthand is not a form
of its own: the grammar desugared it to label = label.
The entries name a subset of the record’s fields, so this is not the whole
field set a Type::Record is, and it is not keyed by label the way that one
is. No label appears twice — Pattern::from_parser reports a repeated one as
Error::RepeatedLabel — and what the pattern matches does not depend on the
order of its entries. They are kept as the source wrote them, as a tuple’s
elements are, and ScopedEnvironment::expose_pattern walks them in that order.
Each entry keeps its label’s span, which is where a diagnostic about that field
points.
Refutable exactly when one of its entries’ patterns is ({ x } cannot fail,
{ x = 0 } can). Nothing here records that, and nothing may read a record
pattern as irrefutable for being a record.
Trait Implementations§
Source§impl Clone for PatternKind
impl Clone for PatternKind
Source§fn clone(&self) -> PatternKind
fn clone(&self) -> PatternKind
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more