#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 上編輯此頁 最後更新: