E0093

E0093#

警告名称:unknown_constr_pat_on_exhaustive_type

在未使用 #non_exhaustive 标记的枚举上使用了 Type::.. 模式。封闭枚举不存在可由该模式匹配的未知未来构造器,因此该模式没有意义。

错误示例#

///|
pub(all) enum Status {
  Ready
  Busy
}

///|
pub fn describe(status : Status) -> String {
  match status {
    Ready => "ready"
    Busy => "busy"
    Status::.. => "unknown"
  }
}

修改建议#

从封闭枚举的匹配中移除 Type::.. 分支。如果该枚举是公共扩展点,并且定义包可能在未来版本中添加构造器,请使用 #non_exhaustive 标记其声明,显式匹配当前所有已知构造器,并将 Type::.. 保留为最后的兼容分支。

///|
#non_exhaustive
pub(all) enum Status {
  Ready
  Busy
}

///|
pub fn describe(status : Status) -> String {
  match status {
    Ready => "ready"
    Busy => "busy"
    Status::.. => "unknown"
  }
}