Commit 8f443eb
authored
zerocopy-derive: Fix panic with raw identifiers (#2788)
* zerocopy-derive: Fix panic with raw identifiers
Stripped `r#` prefix from identifiers when generating internal field/variant names in `zerocopy-derive`.
This prevents panics when using raw identifiers (e.g., `r#type`) in structs or enums.
Added regression tests in `zerocopy-derive/tests/struct_known_layout.rs` and `zerocopy-derive/tests/enum_try_from_bytes.rs`.
Closes #2234
* zerocopy-derive: Fix panic with raw identifiers
Factor out logic to strip `r#` prefix from identifiers into `to_ident_str` helper in `zerocopy-derive/src/ext.rs`.
Use this helper in `zerocopy-derive/src/lib.rs` and `zerocopy-derive/src/enum.rs` when generating internal identifiers.
This prevents panics when using raw identifiers (e.g., `r#type`) in structs or enums.
Added regression tests in `zerocopy-derive/tests/struct_known_layout.rs` and `zerocopy-derive/tests/enum_try_from_bytes.rs`.
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>1 parent e69ede3 commit 8f443eb
File tree
5 files changed
+35
-5
lines changed- zerocopy-derive
- src
- tests
5 files changed
+35
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | | - | |
| 88 | + | |
| 89 | + | |
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
| |||
162 | 164 | | |
163 | 165 | | |
164 | 166 | | |
165 | | - | |
| 167 | + | |
| 168 | + | |
166 | 169 | | |
167 | 170 | | |
168 | 171 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
322 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
323 | 325 | | |
324 | 326 | | |
325 | 327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
642 | 642 | | |
643 | 643 | | |
644 | 644 | | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
0 commit comments