E0076

E0076#

Warning name: lexmatch_first_match

使用 first-match 语义的 lexmatch 已弃用。

lexmatch 表达式使用默认的 first-match 策略时会触发此警告,包括 lexmatch ... with first。在新代码中,普通正则检查应优先使用正则匹配表达式。

错误示例#

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

///|
test {
  ignore(classify)
}

建议#

尽可能将 first-match lexmatch 代码改写为正则匹配表达式。如果确实需要词法分析器风格的 longest-match 行为,请使用 lexmatch ... with longest 显式写出。

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

///|
test {
  ignore(classify)
}