Skip to content

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

@erickt

Description

@erickt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions