E0080

E0080#

Warning name: regex_match_missing_before

lexmatch 模式可能会跳过输入前缀,但该模式既未绑定也未显式忽略这个前缀。

未锚定的正则会从输入开头向后搜索。当匹配必须从开头开始时添加 ^;否则添加 before= 以绑定或忽略跳过的前缀。

错误示例#

///|
pub fn ends_with_digits(input : String) -> Bool {
  lexmatch input {
    re"[0-9]+$" => true
    _ => false
  }
}

建议#

将正则锚定在开头,或使用 before=prefixbefore=_ 显式处理跳过的前缀。

///|
pub fn ends_with_digits(input : String) -> Bool {
  lexmatch input {
    (re"[0-9]+$", before=_) => true
    _ => false
  }
}