#E0073: impl 项不在 trait 中
trait 的 impl 定义了 trait 没有声明的方法或关联类型。删除它,或者把方法移到该类型的固有 impl 中。trait 的泛型参数不是关联类型:把它们写在头部 impl IndexSet<usize, V> for T,而不是写成 type V = ..。
nabi
trait Shape { fn area(self) -> f64; }
struct Sq { s: f64; }
impl Shape for Sq {
fn area(self) -> f64 { self.s * self.s }
fn side(self) -> f64 { self.s }
}
error[E0073]: method `side` is not a member of trait `Shape` --> main.nabi:3:1 | 3 | impl Shape for Sq { | ^^^^
把方法移到固有 impl 中:
nabi
trait Shape { fn area(self) -> f64; }
struct Sq { s: f64; }
impl Shape for Sq {
fn area(self) -> f64 { self.s * self.s }
}
impl Sq {
fn side(self) -> f64 { self.s }
}
println(f"{Sq { s: 3.0 }.side()}");
3
相关错误码:E0072 impl 缺少 trait 项,E0074 impl 项与 trait 不一致
发现错误? 在 GitHub 上编辑此页 最后更新: