-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Why does Pod
not work with 2 generic-fields?
#278
Comments
https://github.com/Lokathor/bytemuck/blob/main/derive/src/traits.rs#L69-L78 |
If the derive macro already assures that the generics are |
The proc-macro is mostly watched over by @fu5ha and @danielhenrymantilla , but yes that sounds correct |
In order to handle the general #![feature(generic_const_exprs)]
pub struct MyStruct<T> {
a: T,
b: u8,
}
pub unsafe trait Pod {}
unsafe
impl<T> Pod for MyStruct<T>
where
// no padding (among other things)
[(); 0 - ( // overflows if the following predicate is true
::core::mem::size_of::<Self>() // is the size of the whole strictly bigger than
// the sum of its parts? It means we got padding.
>
(
0
+ ::core::mem::size_of::<T>() // a
+ ::core::mem::size_of::<u8>() // b
)
) as usize]:,
{}
But this requires Here, we could introduce a very specific subset of syntactic heuristics. The one that could apply here, since it's a pattern which is not completely unheard of, is the "array with named indices", sort to speak, such as struct Name<SingleGeneric> {
a: SingleGeneric,
bunch: SingleGeneric,
of: SingleGeneric,
fields: SingleGeneric,
all: SingleGeneric,
with: SingleGeneric,
the: SingleGeneric,
same: SingleGeneric,
type: SingleGeneric,
}
|
I think at least trying to support deriving when there's all fields the same type would be good. |
Discussed in #277
Originally posted by DasLixou October 15, 2024
I have a struct
and deriving Pod on it errors because multiple generics don't seem to be allowed, but I can't find any documentation of the reason.
So, stupidly asked, why?
The text was updated successfully, but these errors were encountered: