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(IntoBytes)] on generic enums emits code with an arity error. #1642

Closed
Tracked by #671
jswrenn opened this issue Sep 12, 2024 · 0 comments · Fixed by #1838
Closed
Tracked by #671

#[derive(IntoBytes)] on generic enums emits code with an arity error. #1642

jswrenn opened this issue Sep 12, 2024 · 0 comments · Fixed by #1838
Labels

Comments

@jswrenn
Copy link
Collaborator

jswrenn commented Sep 12, 2024

This:

#[derive(IntoBytes)]
#[repr(u8)]
enum MyEnum<T> {
    Foo(T),
}

...expands to this:

unsafe impl<T> ::zerocopy::IntoBytes for MyEnum<T>
where
    T: ::zerocopy::IntoBytes,
    ::zerocopy::util::macro_util::HasPadding<
        MyEnum,
        {
            #[repr(u8)]
            #[allow(dead_code)]
            enum ___ZerocopyTag {
                Foo,
            }
            false
                || ::zerocopy::util::macro_util::core_reexport::mem::size_of::<MyEnum>()
                    != (::zerocopy::util::macro_util::core_reexport::mem::size_of::<
                        ___ZerocopyTag,
                    >()
                        + ::zerocopy::util::macro_util::core_reexport::mem::size_of::<
                            T,
                        >())
        },
    >: ::zerocopy::util::macro_util::ShouldBe<false>,
{
    fn only_derive_is_allowed_to_implement_this_trait() {}
}

...in which MyEnum is unparameterized in the where bound. Consequently, a generic arity error is emitted.

@jswrenn jswrenn added the bug Something isn't working label Sep 16, 2024
@joshlf joshlf added blocking-next-release This issue should be resolved before we release on crates.io blocking-next-release-publicization and removed blocking-next-release This issue should be resolved before we release on crates.io labels Sep 16, 2024
@joshlf joshlf mentioned this issue Sep 23, 2024
87 tasks
jswrenn added a commit that referenced this issue Oct 7, 2024
Use `Self` in padding check instead of type name.

Fixes #1642

Makes progress towards #671
jswrenn added a commit that referenced this issue Oct 7, 2024
Use `Self` in padding check instead of type name.

Fixes #1642

Makes progress towards #671
github-merge-queue bot pushed a commit that referenced this issue Oct 7, 2024
Use `Self` in padding check instead of type name.

Fixes #1642

Makes progress towards #671
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants