Description
My apologies in advance if this is a duplicate or a known limitation. I spent a long while looking and it appears to be similar to #24159 (resolved by #81671), but not quite the same (and this behavior is still present).
Rustc version
Both current stable (1.52.1) and nightly (1.55.0-nightly (2021-06-12 24bdc6d)) fail to compile the following code.
Minimal example
trait Foo {
// There isn't anything special about `Clone` here; it just happens to be
// a trait we can bound this by.
type Bar: Clone;
}
// Because `<F as Foo>::Bar = B`, and `Foo::Bar: Clone`, we'd expect that this
// also requires `B: Clone`.
fn do_thing<F, B>(bar: B) where F: Foo<Bar = B> {
// rustc says that `B` does not implement clone, so there is no `.clone()`
// method we can call here.
bar.clone();
}
I used a function to create the bound conflict here, but it works in a variety of other contexts as well -- I first noticed it in an impl block with the call to clone
in one of the methods.
Essentially, the issue seems to be that the compiler is failing to make the following deduction:
trait
Foo
withFoo::Bar: MyTrait
andT: Foo<Bar = B>
impliesB: MyTrait
If there's anything I can do, I'm happy to help where possible.