E0050
试图实现的 trait 方法的函数参数数量错误。
错误代码示例:
trait Foo {
fn foo(&self, x: u8) -> bool;
}
struct Bar;
// error: method `foo` has 1 parameter but the declaration in trait `Foo::foo`
// has 2
impl Foo for Bar {
fn foo(&self) -> bool { true }
}
例如, Foo trait 具有一个方法 foo,有两个函数参数(&self 和 u8), 但是实现了 foo 的 Bar 类型忽略了 u8 参数。要修复此问题,它们得具有相同的参数:
trait Foo {
fn foo(&self, x: u8) -> bool;
}
struct Bar;
impl Foo for Bar {
fn foo(&self, x: u8) -> bool { // 没问题!
true
}
}
本译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接
我们的翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。
Rust 编译错误索引
关于 LearnKu