E0076

E0076#

Warning name: lexmatch_first_match

Using lexmatch with first-match semantics is deprecated.

This warning is emitted for lexmatch expressions that use the default first-match strategy, including lexmatch ... with first. Prefer regex match expressions for ordinary regex checks in new code.

Erroneous example#

///|
fn classify(input : String) -> String {
  lexmatch input {
    "if" => "keyword"
    _ => "other"
  }
}

///|
test {
  ignore(classify)
}

Suggestion#

Rewrite first-match lexmatch code with a regex match expression when only a boolean result is needed, or with lexscan when the cases return different values. If you need lexer-style longest-match behavior, use lexscan ... with longest.

///|
fn classify(input : String) -> String {
  if input =~ re"^if$" {
    "keyword"
  } else {
    "other"
  }
}

///|
test {
  ignore(classify)
}