E3012#
Record pattern and map pattern cannot be mixed. The key in map pattern must be a literal, while the key in record pattern must be the field name.
Erroneous example#
struct S {
value : Int
}
pub fn S::op_get(self : S, index : String) -> Int? {
if index == "value" {
return Some(self.value)
}
return None
}
fn main {
let s : S = { value: 42 }
match s {
{ "value": value, value } => println("Value is: \{value}") // Error: Record pattern and map pattern cannot be mixed.
_ => println("No value")
}
}
Suggestion#
Remove either the map pattern part or the record pattern part from the pattern.
fn main {
let s : S = { value: 42 }
match s {
{ "value": value } => println("Value is: \{value}")
_ => println("No value")
}
}
Or,
fn main {
let s : S = { value: 42 }
match s {
{ value } => println("Value is: \{value}")
}
}