There's no guarantee that, if
b2 are of type
B: Add, then
b1 + b2 will also be of type
B. Check documentation for the trait for more info.
For future reference, the solution is to change
B: Add to
B: Add<Output = B>.
I've opened a PR to make
rustc suggest this going forward.
This is now in nightly:
error[E0308]: mismatched types --> src/main.rs:12:8 | 5 | impl<B> Add for A<B> | - this type parameter ... 12 | Self(self.0 + rhs.0) | ^^^^^^^^^^^^^^ expected type parameter `B`, found associated type | = note: expected type parameter `B` found associated type `<B as std::ops::Add>::Output` help: consider further restricting this bound | 7 | B: Add + std::ops::Add<Output = B> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.