Skip to content

derive(IntoBytes) fails on repr(C) DSTs with parameterized leading fields #2835

@jswrenn

Description

@jswrenn

For example, compiling:

use zerocopy::IntoBytes;

#[derive(IntoBytes)]
#[repr(C)]
struct Struct {
    leading: Unalign<u32>,
    trailing: [u8]
}

...fails with this error:

error: no rules expected `<`
   --> src/lib.rs:6:18
    |
  6 |     addr: Unalign<u32>,
    |                  ^ no rules expected this token in macro call
    |
note: while trying to match `]`
   --> /playground/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/zerocopy-0.8.27/src/util/macro_util.rs:388:25
    |
388 |     ($t:ty, [$($ts:tt),*]) => {{

The failure arises because our internal repr_c_struct_has_padding macro accepts field types as comma delimited tts, but Unalign<u32> is not a single tt.

We should see if there's a minor patchup we can do to make this work. Unalign<u32> can be made to parse as a tt by parenthesizing it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions