#E0077: 未实现父 trait
一个 trait 要求另一个 trait(它的父 trait),而该类型没有实现它。也为该类型实现父 trait。
nabi
trait Base { fn id(self) -> i32; }
trait Named: Base { fn name(self) -> str; }
struct X {}
impl Named for X { fn name(self) -> str { "x" } }
error[E0077]: `X` implements `Named` but not its supertrait `Base` --> main.nabi:4:1 | 4 | impl Named for X { fn name(self) -> str { "x" } } | ^^^^
也实现父 trait:
nabi
trait Base { fn id(self) -> i32; }
trait Named: Base { fn name(self) -> str; }
struct X {}
impl Base for X { fn id(self) -> i32 { 1 } }
impl Named for X { fn name(self) -> str { "x" } }
println(f"{X {}.name()} {X {}.id()}");
x 1
相关错误码:E0069 不满足 trait 约束,E0072 impl 缺少 trait 项
发现错误? 在 GitHub 上编辑此页 最后更新: