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

Generate bespoke compile time errors for deriving conflicting From implementations #193

Open
JonathanWoollett-Light opened this issue Jun 29, 2022 · 1 comment

Comments

@JonathanWoollett-Light
Copy link

JonathanWoollett-Light commented Jun 29, 2022

An idea for improving explicitness (I may submit a PR in the future)

At the moment:

#[derive(From)]
enum Conflicting {
    A(u8),
    B(u8),
    C(u16)
}
#[test]
fn conflicting_enum() {
    let a = Conflicting::from(4u8);
}

produces:

error[E0119]: conflicting implementations of trait `std::convert::From<u8>` for type `Conflicting`
  --> tests/from.rs:56:10
   |
56 | #[derive(From)]
   |          ^^^^
   |          |
   |          first implementation here
   |          conflicting implementation for `Conflicting`
   |

where it would be better to produce:

error: Conflicting types found when attempting to derive `From` for `Conflicting` (`Conflicting::A(u8)`, `Conflicting::B(u8)`). Please ignore all/all-but-one of the variants.
  --> tests/from.rs:65:5
   |
65 |     std::compile_error!("Conflicting types found when attempting to derive `From` for `Conflicting` (`Conflicting::A(u8)`, Please ignore all/all-but-one of the variants.`Conflicting::B(u8)`).");
   |     
@JelteF
Copy link
Owner

JelteF commented Dec 21, 2023

I agree that this error is not very helpful and that we should improve it. It should be fairly simple. The code we use to derive From could simply track if it is going to generate implementations for identical types (using a HashSet for instance) and if so, fail with a useful error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants