E0076#
Warning name: lexmatch_first_match
此警告描述的是早期实验性的首次匹配 lexmatch 形式,当前编译器不会发出该警告。
当前的 lexmatch 表达式使用 re"..." 分支模式,并且可以采用默认的首次匹配策略。对于单个布尔检查,正则匹配表达式通常更简洁。
错误示例#
///|
fn classify(input : String) -> String {
lexmatch input {
"if" => "keyword"
_ => "other"
}
}
///|
test {
ignore(classify)
}
建议#
请将旧的字符串片段模式语法改写为 re"..." 分支;如果只需要布尔结果,则使用正则匹配表达式。
///|
fn classify(input : String) -> String {
if input =~ re"^if$" {
"keyword"
} else {
"other"
}
}
///|
test {
ignore(classify)
}