You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have run into similar errors to #50133, so that may share the same ultimate cause as mine.
I'm having an issue with the impl<T> From<T> for T blanket implementation causing conflicts with my own blanket implementation of a From trait. For example, if I have a type which implements AsRef<u8>, and From<T: AsRef<[u8]>>, that blanket implementation conflicts, because my implementation of the trait and the trait-bound-from obviously provide a different path for T::from(T). I think this is wrong, though in my specific case I have worked around it by doing From<&'bytes [u8]>, but wrong is wrong :-)
Some sample code:
struct MyType(Vec<u8>);
impl AsRef<[u8]> for MyType {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}
impl<B: AsRef<[u8]> From<B> for MyType {
fn from(src: B) -> Self {
Self(Vec::from(src))
}
}
Resulting error:
error[E0119]: conflicting implementations of trait `std::convert::From<MyType>` for type `MyType`:
--> src/main.rs:10:1
|
10 | impl<B: AsRef<[u8]>> From<B> for MyType {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> std::convert::From<T> for T;
The text was updated successfully, but these errors were encountered:
The second impl could be instantiated with B = MyType because of the first impl. This would collide with the blanket impl in core, shown in the error message. Specialization could possibly allow this, but right now this is intentionally forbidden.
I have run into similar errors to #50133, so that may share the same ultimate cause as mine.
I'm having an issue with the
impl<T> From<T> for T
blanket implementation causing conflicts with my own blanket implementation of aFrom
trait. For example, if I have a type which implementsAsRef<u8>
, andFrom<T: AsRef<[u8]>>
, that blanket implementation conflicts, because my implementation of the trait and the trait-bound-from obviously provide a different path forT::from(T)
. I think this is wrong, though in my specific case I have worked around it by doingFrom<&'bytes [u8]>
, but wrong is wrong :-)Some sample code:
Resulting error:
The text was updated successfully, but these errors were encountered: