E3009#
Record pattern cannot contain only ..
, use wildcard pattern _
instead.
Erroneous example#
struct Point {
x: Int
y: Int
}
fn process_point(p: Point) -> Unit {
match p {
{ .. } => println("Got a point")
//^~~~~~
// Error: Record pattern cannot contain only `..`, use wildcard pattern `_` instead.
}
}
Suggestion#
Use the wildcard pattern _
instead of { .. }
:
struct Point {
x: Int
y: Int
}
fn process_point(p: Point) -> Unit {
match p {
_ => println("Got a point")
}
}
You can also use { .. }
along with other fields if you want to match specific fields:
fn process_point(p: Point) -> Unit {
match p {
{ x: 0, .. } => println("Point on y-axis")
_ => println("Other point")
}
}