Skip to content

Commit ad4ff6f

Browse files
committed
[zerocopy-derive] Fix panic with raw identifiers
Release 0.8.33. Applies the same approach as in #2788, but to new lines of code (that should have used this technique to begin with). gherrit-pr-id: Gc07a814b14897f1beb00786c47a1343e65c9b884
1 parent 8cd798a commit ad4ff6f

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[package]
1616
edition = "2021"
1717
name = "zerocopy"
18-
version = "0.8.32"
18+
version = "0.8.33"
1919
authors = [
2020
"Joshua Liebow-Feeser <joshlf@google.com>",
2121
"Jack Wrenn <jswrenn@amazon.com>",
@@ -112,13 +112,13 @@ __internal_use_only_features_that_work_on_stable = [
112112
]
113113

114114
[dependencies]
115-
zerocopy-derive = { version = "=0.8.32", path = "zerocopy-derive", optional = true }
115+
zerocopy-derive = { version = "=0.8.33", path = "zerocopy-derive", optional = true }
116116

117117
# The "associated proc macro pattern" ensures that the versions of zerocopy and
118118
# zerocopy-derive remain equal, even if the 'derive' feature isn't used.
119119
# See: https://github.com/matklad/macro-dep-test
120120
[target.'cfg(any())'.dependencies]
121-
zerocopy-derive = { version = "=0.8.32", path = "zerocopy-derive" }
121+
zerocopy-derive = { version = "=0.8.33", path = "zerocopy-derive" }
122122

123123
[dev-dependencies]
124124
# More recent versions of `either` have an MSRV higher than ours.
@@ -142,4 +142,4 @@ testutil = { path = "testutil" }
142142
# CI test failures.
143143
trybuild = { version = "=1.0.89", features = ["diff"] }
144144
# In tests, unlike in production, zerocopy-derive is not optional
145-
zerocopy-derive = { version = "=0.8.32", path = "zerocopy-derive" }
145+
zerocopy-derive = { version = "=0.8.33", path = "zerocopy-derive" }

zerocopy-derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[package]
1010
edition = "2021"
1111
name = "zerocopy-derive"
12-
version = "0.8.32"
12+
version = "0.8.33"
1313
authors = ["Joshua Liebow-Feeser <joshlf@google.com>", "Jack Wrenn <jswrenn@amazon.com>"]
1414
description = "Custom derive for traits from the zerocopy crate"
1515
license = "BSD-2-Clause OR Apache-2.0 OR MIT"

zerocopy-derive/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,8 @@ fn derive_has_field_struct_union(
764764
}
765765

766766
let field_tokens = fields.iter().map(|(vis, ident, _)| {
767-
let ident = Ident::new(&format!("ẕ{}", ident), ident.span());
767+
let ident_str = to_ident_str(ident);
768+
let ident = Ident::new(&format!("ẕ{}", ident_str), ident.span());
768769
quote!(
769770
#vis enum #ident {}
770771
)
@@ -783,7 +784,8 @@ fn derive_has_field_struct_union(
783784
Data::Enum(..) | Data::Struct(..) => false,
784785
};
785786
let has_fields = fields.iter().map(move |(_, ident, ty)| {
786-
let field_token = Ident::new(&format!("ẕ{}", ident), ident.span());
787+
let ident_str = to_ident_str(ident);
788+
let field_token = Ident::new(&format!("ẕ{}", ident_str), ident.span());
787789
let field: Box<Type> = parse_quote!(#field_token);
788790
let field_id: Box<Expr> = parse_quote!({ #zerocopy_crate::ident_id!(#ident) });
789791
ImplBlockBuilder::new(

zerocopy-derive/tests/struct_try_from_bytes.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,11 @@ struct A;
249249
struct B {
250250
a: A,
251251
}
252+
253+
#[derive(imp::TryFromBytes)]
254+
#[repr(C)]
255+
struct RawType {
256+
r#type: u8,
257+
}
258+
259+
util_assert_impl_all!(RawType: imp::TryFromBytes);

0 commit comments

Comments
 (0)