Open
Description
Consider the following code:
#![crate_type="lib"]
use std::marker::PhantomData;
trait Foo {
type Type: Qux;
}
struct Bar<T>(PhantomData<T>);
trait Qux {}
impl<T: Foo> From<T::Type> for Bar<T> {
fn from(t: T::Type) -> Self {
Bar(PhantomData)
}
}
This fails to build with:
error[E0119]: conflicting implementations of trait `std::convert::From<Bar<_>>` for type `Bar<_>`:
--> src/lib.rs:13:1
|
13 | impl<T: Foo> From<T::Type> for Bar<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> std::convert::From<T> for T;
This implies the compiler thinks T::Type
might be Bar<T>
, but because of the Qux
bound, and the fact that there is no impl<T> Qux for Bar<T> {}
, it's not possible.
In fact, doing some handholding works: impl<T: Foo<Type=U>, U: Qux> From<U> for Bar<T>
yields no error and is equivalent, albeit unnecessarily verbose.