E3019

E3019#

包含的范围模式 a..=b 的上界不能是 _

书写 a..=_ 没有意义,因为 _ 是一个通配符,可以匹配任何值。"等于任何值" 的含义不明确。如果你想表达 "大于或等于 a" 的含义,你可以使用 a..<_

错误示例#

///|
fn describe(value : Int) -> String {
  match value {
    0..=_ => "non-negative"
    _ => "negative"
  }
}

///|
test {
  inspect(describe(0), content="non-negative")
}

建议#

..=_ 替换为 ..<_

///|
fn describe(value : Int) -> String {
  match value {
    0..<_ => "non-negative"
    _ => "negative"
  }
}

///|
test {
  inspect(describe(0), content="non-negative")
}