E0087#
警告名称:guard_inexhaustive
不带 else 子句的 guard 可能失败。当条件为假或模式无法匹配时,程序将隐式终止。
错误示例#
///|
pub fn unwrap(value : Int?) -> Int {
guard value is Some(result)
result
}
修改建议#
添加 else 子句处理失败;如果本来就需要终止程序,请使用 guard!。
///|
pub fn unwrap_or_zero(value : Int?) -> Int {
guard value is Some(result) else { 0 }
result
}
///|
pub fn require_some(value : Int?) -> Int {
guard! value is Some(result)
result
}