E4063#
尽管定义了 impl
,但类型未实现特征。
此误差可进一步分为 5 种情况:
Method is missing
Implementation is private
方法类型不匹配
不满足约束条件
方法包含未解析的类型参数
错误示例#
Method is missing#
trait Number {
to_int(Self) -> Int
to_float(Self) -> Float
}
type A Int
impl Number for A with to_int(self : A) -> Int {
//^~~~~~~~~~~~~~~
// Error: Type A does not implement trait Number, although an `impl` is defined.
// hint:
// method to_float is missing.
self._
}
建议#
根据错误信息提供的提示修改代码。对于上面的示例,你可以将缺少的方法 to_float
添加到类型 A
。
impl Number for A with to_float(self : A) -> Float {
self._.to_float()
}