E3007#
记录模式中的 .. 位置错误。请将 .. 放在模式中最后一个字段之后。
错误示例#
pub(all) struct S {
a : Int
b : Int
c : Int
}
fn sum_selected(s : S) -> Int {
let { a, .., c } = s
a + c
}
test {
inspect(sum_selected({ a: 1, b: 2, c: 3 }), content="4")
}
建议#
将 .. 移到记录模式的末尾,放在所有需要绑定的字段之后:
///|
pub(all) struct S {
a : Int
b : Int
c : Int
}
///|
fn sum_selected(s : S) -> Int {
let { a, c, .. } = s
a + c
}
///|
test {
inspect(sum_selected({ a: 1, b: 2, c: 3 }), content="4")
}