zerocopy-derive: Fix panic with raw identifiers #2788
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixed a bug where using raw identifiers (e.g.
r#type) as field names in structs or variants in enums causedzerocopy-deriveto panic. The panic occurred because the macro was attempting to create new identifiers by concatenating a prefix with the raw identifier string (includingr#), resulting in invalid identifiers like__Zerocopy_Field_r#type. The fix involves stripping ther#prefix before concatenation. Regression tests were added tozerocopy-derive/tests/struct_known_layout.rsandzerocopy-derive/tests/enum_try_from_bytes.rs.Closes #2234
PR created automatically by Jules for task 10899143724396362571 started by @joshlf