E0081#
Warning name: regex_match_missing_after
lexmatch 模式可能会留下未匹配的输入后缀,但该模式既未绑定也未显式忽略这个后缀。
当匹配必须在输入末尾结束时添加 $;否则添加 after= 以绑定或忽略剩余后缀。
错误示例#
///|
pub fn starts_with_digits(input : String) -> Bool {
lexmatch input {
re"^[0-9]+" => true
_ => false
}
}
建议#
将正则锚定在结尾,或使用 after=suffix 或 after=_ 显式处理后缀。
///|
pub fn starts_with_digits(input : String) -> Bool {
lexmatch input {
(re"^[0-9]+", after=_) => true
_ => false
}
}