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

Derive for newtypes with generics #19

Open
adiba opened this issue Oct 9, 2018 · 3 comments · May be fixed by #37
Open

Derive for newtypes with generics #19

adiba opened this issue Oct 9, 2018 · 3 comments · May be fixed by #37

Comments

@adiba
Copy link

adiba commented Oct 9, 2018

#[derive(Float)]
struct A<T:Float>(T);

Here, float will try to implement Float for T, but T is a parameter.
Instead, it should:

impl<T:Float> Float for A<T>{...}
@cuviper
Copy link
Member

cuviper commented Oct 9, 2018

Here, float will try to implement Float for T, but T is a parameter.

It is implementing for A, but it's missing the generic parameter. The expanded code looks like:

        impl _num_traits::Float for A {
            fn nan() -> Self { A(<T as _num_traits::Float>::nan()) }
...
error[E0412]: cannot find type `T` in this scope
 --> src/lib.rs:8:19
  |
8 | struct A<T:Float>(T);
  |                   ^ did you mean `A`?

error[E0243]: wrong number of type arguments: expected 1, found 0
 --> src/lib.rs:8:8
  |
8 | struct A<T:Float>(T);
  |        ^ expected 1 type argument

error: aborting due to 2 previous errors

Instead, it should:

impl<T:Float> Float for A<T>{...}

Yes, that should work.

We should see if there are other derive crates we can use as an example of how to produce generic args and constraints properly.

@adiba
Copy link
Author

adiba commented Oct 11, 2018

https://crates.io/crates/derive_more
This one performs well on this example for a handful of std-traits.

@asfishman
Copy link

Any updates on this issue?

@oli-cosmian oli-cosmian linked a pull request Jun 26, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants