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

Request to add extra info: cannot implement both From and TryFrom #66

Open
bnm3k opened this issue Mar 10, 2023 · 0 comments
Open

Request to add extra info: cannot implement both From and TryFrom #66

bnm3k opened this issue Mar 10, 2023 · 0 comments

Comments

@bnm3k
Copy link

bnm3k commented Mar 10, 2023

In the TryFrom section, is it worth mentioning that you cannot implement both From and TryFrom since if From is implemented for a given type T, an infallible TryFrom is also auto-implemented for you. Therefore you end up with conflicting trait implementations for the same type. For example, let's say you implement both From and TryFrom for Point, you get the following error:

error[E0119]: conflicting implementations of trait `TryFrom<(i32, i32)>` for type `Point`
  --> src/main.rs:22:1
   |
22 | impl TryFrom<(i32, i32)> for Point {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: conflicting implementation in crate `core`:
           - impl<T, U> TryFrom<U> for T
             where U: Into<T>;

For more information about this error, try `rustc --explain E0119`.
error: could not compile `foo` due to previous error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant