E0090

E0090#

Warning name: unused_lexcase

A lexmatch or lexscan branch can never be selected.

This happens when an earlier branch takes precedence for every input matched by the later branch, or when the branch's regex matches no input. An unnecessary catch-all after exhaustive regex cases produces the same warning.

Erroneous example#

///|
pub fn classify(text : String) -> String {
  lexmatch text {
    re"^a.*$" => "starts with a"
    re"^ab.*$" => "starts with ab"
    _ => "other"
  }
}

The first branch already handles every string that starts with "ab", so the second branch is unreachable under first-match semantics.

Suggestion#

Remove the unreachable branch, or move a more specific regex before the branch that shadows it.

///|
pub fn classify(text : String) -> String {
  lexmatch text {
    re"^ab.*$" => "starts with ab"
    re"^a.*$" => "starts with a"
    _ => "other"
  }
}