E0087

E0087#

Warning name: guard_inexhaustive

A guard without an else clause may fail. When its condition is false or its pattern does not match, it would implicitly terminate the program.

Erroneous example#

///|
pub fn unwrap(value : Int?) -> Int {
  guard value is Some(result)
  result
}

Suggestion#

Add an else clause to handle failure, or use guard! when termination is intentional.

///|
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
}