Skip to content

Conversation

@joshlf
Copy link
Member

@joshlf joshlf commented Jan 7, 2026

joshlf added 5 commits January 7, 2026 21:22
Introduce `CastExact: Cast`, which denotes that a `Cast` exactly
preserves the set of referent bytes. Add this bound to
`SizeEq::CastFrom`, allowing `SizeEq` to be safe to implement.

gherrit-pr-id: G57ec07c3841271440bbaf40cab04b942cbdbddb9
Previously, we allowed for `Src: Read<A, R>` and `Dst: Read<A, S>` for
different `R` and `S` "reason" parameters. This is an unnecessary degree
of freedom (two types are only ever `Read<A>` for a particular `A` for
the same reason – either because `A = Exclusive` or because both types
implement `Immutable`). This degree of freedom required more verbose
type annotations by callers.

gherrit-pr-id: Gbec926233303ce55c894f8ba65c939dd42690530
gherrit-pr-id: Gbe8d7edd150d80731c79815685c596ed88460ae7
gherrit-pr-id: G7691845b6b02e9f3d9578435d732bacfa6ca674f
gherrit-pr-id: G6cefafff5fb576d45dbb1a303780ca47c3ea03e5
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @joshlf, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on refactoring the zerocopy-derive crate to incorporate the ReadOnly wrapper type within the is_bit_valid derivation logic. The changes aim to improve type safety and consistency in pointer manipulation by explicitly marking read-only references and standardizing the use of WrappedProjection for field and variant projections, leading to a more robust and idiomatic implementation.

Highlights

  • Integration of ReadOnly Type: The derive_is_bit_valid function now explicitly uses the ReadOnly wrapper type for casting and projecting enum variants and raw enum structures, enhancing type safety by clearly indicating read-only access.
  • Transition to WrappedProjection: The Projection type parameter in various pointer casting operations has been consistently replaced with WrappedProjection across derive_is_bit_valid, derive_try_from_bytes_struct, and derive_try_from_bytes_union.
  • Refined Pointer Casting: Some unsafe blocks around cast_unchecked calls have been removed in favor of cast with ReadOnly, and field projection logic has been updated to use project_transmute_unchecked with WrappedProjection for struct and union fields.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the is_bit_valid derive logic to use ReadOnly and a new WrappedProjection mechanism. This improves safety by removing an unsafe block in zerocopy-derive/src/enum.rs and makes the projection logic more consistent across the derive implementations. The changes look good, but there are a few places where the old code has been commented out. These should be removed to improve code clarity.

Comment on lines +443 to +446
// let tag_ptr = raw_enum.reborrow().project::<
// (),
// { #zerocopy_crate::ident_id!(tag) }
// >()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This commented-out code appears to be from a previous implementation. Please remove it to improve code clarity.

WrappedProjection<_, _, { #zerocopy_crate::STRUCT_VARIANT_ID }, { #zerocopy_crate::ident_id!(variants) }>,
_,
>();
// let variants = raw_enum.project::<_, { #zerocopy_crate::ident_id!(variants) }>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This commented-out line seems to be leftover from a previous implementation. Please remove it.

Comment on lines +917 to +920
// let field_candidate = candidate.reborrow().project::<
// _,
// { #zerocopy_crate::ident_id!(#field_names) }
// >();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This commented-out code seems to be from a previous implementation. Please remove it to improve code clarity.

@joshlf joshlf force-pushed the G7691845b6b02e9f3d9578435d732bacfa6ca674f branch 14 times, most recently from e6fab2d to 6a4dcd8 Compare January 9, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant