E4216#
编译器诊断名称:lexscan_catchall_binder_not_supported。
流式 lexscan 的兜底分支使用了绑定模式。
流式分支只在正则匹配时消费输入。最后的兜底分支还负责处理输入结束,因此不会绑定匹配到的子串。该分支应使用 _,需要匹配文本的正则分支则通过 as 绑定。
错误示例#
///|
pub fn next_token(lexbuf : @lexbuf.Lexbuf) -> String {
lexscan lexbuf {
(re"^[a-z]+" as word) => word.to_owned()
rest => rest.to_owned()
}
}
建议#
将兜底分支的绑定变量替换为 _。
///|
pub fn next_token(lexbuf : @lexbuf.Lexbuf) -> String {
lexscan lexbuf {
(re"^[a-z]+" as word) => word.to_owned()
_ => "end"
}
}