Closed
Description
I tried this code (playground link):
use core::ops::AddAssign;
trait TraitA<B>: Copy + AddAssign<B> + AddAssign<Self> {}
trait TraitC<B> { type Thing: TraitA<B>; }
fn use_c<B, C: TraitC<B>>(mut a: C::Thing, b: B) {
a += b; // errors
a += a;
}
I expected this to compile, because the trait bounds on TraitA
are sufficient. Instead, rustc
fails to find the AddAssign<B>
bound for C::Thing
, and errors out with the following error message:
|
7 | fn use_c<B, C: TraitC<B>>(mut a: C::Thing, b: B) {
| - this type parameter
8 | a += b; // errors
| ^ expected associated type, found type parameter `B`
|
= note: expected associated type `<C as TraitC<B>>::Thing`
found type parameter `B`
help: consider further restricting this bound
|
7 | fn use_c<B, C: TraitC<B> + TraitC<B, Thing = B>>(mut a: C::Thing, b: B) {
| ^^^^^^^^^^^^^^^^^^^^^^
(Note that the help
message, while technically correct, is actually unhelpful here.)
Meta
This bug occurs in the latest stable, beta, and nightly (this can be verified on the playground link).
This might be related to #41756.