Closed huanyusun closed 5 years ago
trait Add<RHS, Output> { fn add(self, rhs: RHS) -> Output; //此处方法名应该为 my_add } impl Add<i32, i32> for i32 { fn my_add(self, rhs: i32) -> i32 { self + rhs } } impl Add<u32, i32> for u32 { fn my_add(self, rhs: u32) -> i32 { (self + rhs) as i32 } } fn main() { let (a, b, c, d) = (1i32, 2i32, 3u32, 4u32); let x: i32 = a.my_add(b); let y: i32 = c.my_add(d); assert_eq!(x, 3i32); assert_eq!(y, 7i32); }
$ rustc -V rustc 1.34.0 (91856ed52 2019-04-10)
error[E0407]: method `my_add` is not a member of trait `Add` --> src/main.rs:6:5 | 6 | / fn my_add(self, rhs: i32) -> i32 { 7 | | self + rhs 8 | | } | |_____^ not a member of trait `Add` error[E0407]: method `my_add` is not a member of trait `Add` --> src/main.rs:12:5 | 12 | / fn my_add(self, rhs: u32) -> i32 { 13 | | (self + rhs) as i32 14 | | } | |_____^ not a member of trait `Add` error[E0046]: not all trait items implemented, missing: `add` --> src/main.rs:5:1 | 2 | fn add(self, rhs: RHS) -> Output; | --------------------------------- `add` from trait ... 5 | impl Add<i32, i32> for i32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `add` in implementation error[E0046]: not all trait items implemented, missing: `add` --> src/main.rs:11:1 | 2 | fn add(self, rhs: RHS) -> Output; | --------------------------------- `add` from trait ... 11 | impl Add<u32, i32> for u32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `add` in implementation error: aborting due to 4 previous errors
@huanyusun 感谢反馈,这个已经勘误过了。可以关注issues里closed列表,是曾经的勘误。
页码与行数
代码错误
Rust版本
错误信息