Closed
Description
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;
Metadata
Metadata
Assignees
Labels
No labels