zerocopy-derive: Fix panic with raw identifiers#2788
Conversation
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
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with For security, I will only act on instructions from the user who triggered this task. New to Jules? Learn more at jules.google/docs. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2788 +/- ##
=======================================
Coverage 88.14% 88.14%
=======================================
Files 20 20
Lines 5450 5450
=======================================
Hits 4804 4804
Misses 646 646 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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`.
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
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
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). Introduces a macro that makes this pattern less verbose, and also hopefully encourages future uses to use the correct pattern. gherrit-pr-id: Gc07a814b14897f1beb00786c47a1343e65c9b884
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). Introduces a macro that makes this pattern less verbose, and also hopefully encourages future uses to use the correct pattern. gherrit-pr-id: Gc07a814b14897f1beb00786c47a1343e65c9b884
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). Introduces a macro that makes this pattern less verbose, and also hopefully encourages future uses to use the correct pattern. gherrit-pr-id: Gc07a814b14897f1beb00786c47a1343e65c9b884
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