pub type Light { Red, Amber, Green } pub fn complete :: l: Light -> Int { match l { Red -> 0, Amber -> 1, Green -> 2 } } pub fn missing_variant :: l: Light -> Int { match l //~ ERROR E0301 `Green` is not covered { Red -> 0, Amber -> 1 } } pub fn nested :: o: Option> -> Int { match o //~ ERROR E0301 `Some(None)` is not covered { None -> 0, Some(Some(n)) -> n } } pub fn lists :: xs: List -> Int { match xs //~ ERROR E0301 `[_, ..]` is not covered { [] -> 0, [x] -> x, [_, _, ..] if True -> 2 } } pub fn tuples :: p: (Bool, Bool) -> Int { match p //~ ERROR E0301 `(False, False)` is not covered { (True, _) -> 1, (_, True) -> 2 } } pub fn literals :: n: Int -> String { match n //~ ERROR E0301 `_` is not covered { 0 -> "zero", 1 -> "one" } } pub fn literals_ok :: n: Int -> String { match n { 0 -> "zero", _ -> "other" } } pub fn or_patterns :: l: Light -> Bool { match l { Red | Amber -> False, Green -> True } } pub fn unreachable :: l: Light -> Int { match l { _ -> 0 , Red -> 1 //~ WARN W0301 unreachable } } pub fn unreachable_after_cover :: o: Option -> Int { match o { Some(_) -> 1 , None -> 0 , Some(5) -> 5 //~ WARN W0301 unreachable } } pub fn labelled :: u: Option -> Int { match u { Some(Red) -> 0, Some(_) -> 1, None -> 2 } } pub fn refutable_let :: o: Option -> Int { let Some(x) = o //~ ERROR E0302 `None` is not covered x } pub fn irrefutable_let :: p: (Int, Int) -> Int { let (a, b) = p a + b } pub fn never_needs_no_arms :: n: Never -> Int { match n {} } // A bodyless type has no constructors either (ADR 0059); `@builtin` // types like `Int` stay inhabited (see `int_needs_arms`). type Foreign pub fn bodyless_needs_no_arms :: x: Foreign -> Int { match x {} } // Without arms, the scrutinee's type decides (issue #218). pub fn int_needs_arms :: n: Int -> String { match n {} //~ ERROR E0301 `_` is not covered } pub fn bool_needs_arms :: b: Bool -> String { match b {} //~ ERROR E0301 `False` is not covered } pub fn any_type_needs_arms :: x: a -> Int { match x {} //~ ERROR E0301 `_` is not covered } pub fn result_missing_error :: r: Result -> Int { match r //~ ERROR E0301 `Error(_)` is not covered { Ok(n) -> n } } pub fn result_missing_ok :: r: Result -> Int { match r //~ ERROR E0301 `Ok(_)` is not covered { Error(_) -> 0 } } pub fn result_nested :: r: Result, String> -> Int { match r //~ ERROR E0301 `Ok(None)` is not covered { Ok(Some(n)) -> n, Error(_) -> 0 } } pub fn result_complete :: r: Result, String> -> Int { match r { Ok(Ok(n)) -> n, Ok(Error(_)) | Error(_) -> 0 } } pub fn result_refutable_let :: r: Result -> Int { let Ok(n) = r //~ ERROR E0302 `Error(_)` is not covered n }