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

zerocopy-derive lost ability to parse raw identifiers in 0.8.13 #2234

Open
erickt opened this issue Jan 13, 2025 · 0 comments
Open

zerocopy-derive lost ability to parse raw identifiers in 0.8.13 #2234

erickt opened this issue Jan 13, 2025 · 0 comments

Comments

@erickt
Copy link

erickt commented Jan 13, 2025

zerocopy-derive used to support struct fields with raw identifiers, like r#type, up to 0.8.12, but this was broken in 0.8.13. For example:

use zerocopy::byteorder::network_endian::U16;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout, Unaligned};

#[repr(C)]
#[derive(KnownLayout, FromBytes, IntoBytes, Immutable, Unaligned, Debug, PartialEq, Eq, Clone)]
pub struct IcmpHeader {
    r#type: u8,
    code: u8,
    checksum: U16,
    id: U16,
    sequence: U16,
}

This compiles successfully with this Cargo.toml:

[package]
name = "foo"
version = "0.1.0"
edition = "2021"

[dependencies]
zerocopy = { version = "=0.8.12", features = ["derive"] }

But fails with this Cargo.toml:

[package]
name = "foo"
version = "0.1.0"
edition = "2021"

[dependencies]
zerocopy = { version = "=0.8.13", features = ["derive"] }

with this error message:

% cargo build
    Updating crates.io index
   Compiling foo v0.1.0 (/usr/local/google/home/etryzelaar/foo)
error: proc-macro derive panicked
 --> src/lib.rs:5:10
  |
5 | #[derive(KnownLayout, FromBytes, IntoBytes, Immutable, Unaligned, Debug, PartialEq, Eq, Clone)]
  |          ^^^^^^^^^^^
  |
  = help: message: `"__Zerocopy_Field_r#type"` is not a valid identifier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant