-
Notifications
You must be signed in to change notification settings - Fork 77
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
fix(derive): require Default
trait bound for the skipped field type, rather than for its type parameters
#340
Conversation
Now that I think about it, it seems, that the same change could be made for the requirements of |
It used to be so one day in borsh, but then derive for recursive types didn't work |
I'm declining this now until we finish with #337, which is a pretty big chunk all by itself. Current approach (copied from serde) with bounds on type parameters is simple to reason about, as it's final (you see the final bounds on actual type parameters, there's no complex logic and assumtions of what compiler might infer for OpaqueType<T, V> : Trait). Escape hatch with Though i don't foresee any problems doing it for BorshDeserialize + Default combination, but a little more thought has to be given to potential problematic cases, if they can arise. Please adjust pr #337 to not depend on this in the case if you've already done otherwise. |
The pr didn't have a docs update on how the derived bounds would behave now, and it clearly lacked a primer of various non-default cases how the compiler will behave, e.g. when OpaqueStruct<T, V> requires some bounds (not Default trait) in its Default implementation. |
@DanikVitek i've thought about this a bit. I guess the optimal implementation would be to:
#[derive(Default)]
struct A<X, Y, Z> {
x: X,
y: Y,
z: Z,
} #[automatically_derived]
impl<
X: ::core::default::Default,
Y: ::core::default::Default,
Z: ::core::default::Default,
> ::core::default::Default for A<X, Y, Z> {
#[inline]
fn default() -> A<X, Y, Z> {
A {
x: ::core::default::Default::default(),
y: ::core::default::Default::default(),
z: ::core::default::Default::default(),
}
}
} |
But then, in case if the type is not standard and is just similarly-named, the |
Fixes #339