E0087

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
}