Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementing From<<ForeignTy as ToOwned>::Owned> for LocalTy, errors with conflicting implementation #107514

Open
PizzasBear opened this issue Jan 31, 2023 · 3 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-coherence Area: Coherence A-traits Area: Trait system C-bug Category: This is a bug. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@PizzasBear
Copy link
Contributor

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
@PizzasBear PizzasBear added the C-bug Category: This is a bug. label Jan 31, 2023
@kadiwa4
Copy link
Contributor

kadiwa4 commented Jan 31, 2023

Is this issue about the conflicting implementation or about the inconsistent error messages?

@PizzasBear
Copy link
Contributor Author

I opened the issue mostly for the conflicting implementation, I just found the inconsistent error messages and decided to mention them here.

@ChrisDenton ChrisDenton added the needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. label Jul 16, 2023
@Enselic
Copy link
Member

Enselic commented Jul 30, 2024

Triage: Thanks for reporting. The code currently has quite a few problems. Can you please reduce this down to only one error? Analyzing and explaining 5 errors makes it hard to focus on what the exact issue and bug is. Thanks!

@fmease fmease added A-traits Area: Trait system A-associated-items Area: Associated items (types, constants & functions) T-types Relevant to the types team, which will review and decide on the PR/issue. A-coherence Area: Coherence and removed needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. labels Nov 12, 2024
@fmease fmease changed the title implementing From<<builtin as ToOwned>::Owned>, errors with conflicting implementation implementing From<<ForeignTy as ToOwned>::Owned> for LocalTy, errors with conflicting implementation Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-coherence Area: Coherence A-traits Area: Trait system C-bug Category: This is a bug. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants