Open
Description
I tried this code:
use rand::rngs::StdRng;
#[derive(Clone)]
struct Foo;
impl From<<i32 as ToOwned>::Owned> for Foo {
fn from(_: <i32 as ToOwned>::Owned) -> Self {
Self
}
}
impl From<<str as ToOwned>::Owned> for Foo {
fn from(_: i32, _: String) -> u32 {
Self
}
}
impl From<<bool as ToOwned>::Owned> for Foo {
fn from(_: <bool as ToOwned>::Owned) -> Self {
Self
}
fn asdf() {}
}
impl From<<StdRng as ToOwned>::Owned> for Foo {}
#[derive(Clone)]
struct Bar;
impl From<<Bar as ToOwned>::Owned> for Foo {
fn from(foo: <i32 as ToOwned>::Owned) -> Self {
Self
}
}
fn main() {}
Compiling it, I got these errors:
error[E0407]: method `asdf` is not a member of trait `From`
--> src/main.rs:22:5
|
22 | fn asdf() {}
| ^^^^^^^^^^^^ not a member of trait `From`
error[E0119]: conflicting implementations of trait `From<Foo>` for type `Foo`
--> src/main.rs:6:1
|
6 | impl From<<i32 as ToOwned>::Owned> for Foo {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> From<T> for T;
error[E0119]: conflicting implementations of trait `From<Foo>` for type `Foo`
--> src/main.rs:12:1
|
12 | impl From<<str as ToOwned>::Owned> for Foo {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> From<T> for T;
error[E0119]: conflicting implementations of trait `From<Foo>` for type `Foo`
--> src/main.rs:18:1
|
18 | impl From<<bool as ToOwned>::Owned> for Foo {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> From<T> for T;
error[E0119]: conflicting implementations of trait `From<Foo>` for type `Foo`
--> src/main.rs:25:1
|
25 | impl From<<StdRng as ToOwned>::Owned> for Foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> From<T> for T;
Some errors have detailed explanations: E0119, E0407.
For more information about an error, try `rustc --explain E0119`.
error: could not compile `test-issue` due to 5 previous errors
It seems that only structs defined in external crates trigger this error. This results in no errors about fn from()
not being defined or its signature being wrong, but there is an error about other functions being defined that are not part of From
.
Meta
rustc --version --verbose
:
rustc 1.67.0 (fc594f156 2023-01-24)
binary: rustc
commit-hash: fc594f15669680fa70d255faec3ca3fb507c3405
commit-date: 2023-01-24
host: x86_64-unknown-linux-gnu
release: 1.67.0
LLVM version: 15.0.6