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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
Pratyush commentedon Sep 17, 2020
Update: this compiles successfully with
chalk
; the output ofis
tesuji commentedon Sep 17, 2020
Pratyush commentedon Oct 10, 2020
Update: this compiles on the latest nightly. Is there a way to figure out what changed?
tesuji commentedon Oct 11, 2020
You could try out bisect-rustc to find which nightly and possibly which PR fix the problem: https://github.com/rust-lang/cargo-bisect-rustc/blob/master/TUTORIAL.md
Pratyush commentedon Oct 11, 2020
Ahh I think it was this (see “ambiguous projection bounds”) #73905 (comment)
Pratyush commentedon Nov 16, 2020
Can confirm that this is fixed due to #73905; closing.