Skip to content

Conversation

@jswrenn
Copy link
Collaborator

@jswrenn jswrenn commented Dec 5, 2025


This PR is on branch fields.

Latest Update: v11 — Compare vs v10

📚 Full Patch History

Links show the diff between the row version and the column version.

Version Base v1 v2 v3 v4 v5 v6 v7 v8 v9 v10
v11 Base v1 v2 v3 v4 v5 v6 v7 v8 v9 v10
v10 Base v1 v2 v3 v4 v5 v6 v7 v8 v9
v9 Base v1 v2 v3 v4 v5 v6 v7 v8
v8 Base v1 v2 v3 v4 v5 v6 v7
v7 Base v1 v2 v3 v4 v5 v6
v6 Base v1 v2 v3 v4 v5
v5 Base v1 v2 v3 v4
v4 Base v1 v2 v3
v3 Base v1 v2
v2 Base v1
v1 Base

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jswrenn, 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 establishes a code generation framework within the project, specifically to automate the creation of boilerplate trait implementations. The primary application demonstrated is the automatic derivation of the Immutable trait for Rust tuples of varying arities, which previously required manual implementation. This change streamlines the process of extending trait support to common Rust types and refactors the internal derive macro logic for improved flexibility.

Highlights

  • New Code Generation Mechanism: A new code generation system has been introduced, primarily through the addition of zerocopy-derive/src/codegen.rs, to automate the creation of boilerplate code.
  • Immutable Trait Implementations for Tuples: The new code generation mechanism is immediately utilized to automatically generate Immutable trait implementations for Rust tuples ranging from 1 to 26 elements, located in the new src/generated.rs file.
  • Refactored ImplBlockBuilder API: The ImplBlockBuilder in zerocopy-derive has been refactored with a new from_derive_input constructor, simplifying its usage and making it more flexible to handle both named types (structs, enums, unions) and unnamed types (tuples) for trait implementations.
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 introduces a code generation mechanism to implement Immutable for tuples, which is a great addition. The implementation is cleverly done by refactoring ImplBlockBuilder to be more generic and reusing it within a test function that generates the code. The refactoring across zerocopy-derive to use the new ImplBlockBuilder::from_derive_input constructor and consolidate logic for structs, enums, and unions is a significant improvement, making the code cleaner and more maintainable.

I have one suggestion to improve the developer experience around the code generation test. Otherwise, the changes look solid and well-executed.

Comment on lines +66 to +79
fn codegen() {
let path = {
use std::path::PathBuf;
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
assert!(path.pop());
path.push("src");
path.push("generated.rs");
path
};

let generated = [HEADER, &tuples()].map(ToString::to_string).join("\n");

std::fs::write(path, generated.as_bytes()).unwrap();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The current implementation of codegen as a test has the side effect of modifying the source tree whenever cargo test is run. This can be surprising for developers and lead to a dirty worktree.

A more robust pattern is to make the test verify that the generated code is up-to-date, and only update it when an environment variable is set. This makes cargo test a verification step, and updating the code an explicit action. This also improves CI, as it can fail if generated code is not checked in.

I've also replaced unwrap() with expect() to provide more helpful error messages.

fn codegen() {
    let path = {
        use std::path::PathBuf;
        let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
        assert!(path.pop());
        path.push("src");
        path.push("generated.rs");
        path
    };

    let generated = [HEADER, &tuples()].map(ToString::to_string).join("\n");

    if std::env::var("ZEROCOPY_UPDATE_CODEGEN").is_ok() {
        std::fs::write(&path, generated.as_bytes())
            .expect("failed to write generated code to src/generated.rs");
    } else {
        let existing = std::fs::read_to_string(&path)
            .expect("failed to read existing generated code from src/generated.rs");
        if existing != generated {
            panic!("\n\nGenerated code is out of date. Run `ZEROCOPY_UPDATE_CODEGEN=1 cargo test` to update.\n\n");
        }
    }
}

@codecov-commenter
Copy link

codecov-commenter commented Dec 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.05%. Comparing base (33f3fb6) to head (86f1080).

Additional details and impacted files
@@                            Coverage Diff                             @@
##           G9e7039c715e1ec53e6d860909bb0d618898fd46b    #2844   +/-   ##
==========================================================================
  Coverage                                      92.05%   92.05%           
==========================================================================
  Files                                             20       20           
  Lines                                           5812     5812           
==========================================================================
  Hits                                            5350     5350           
  Misses                                           462      462           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jswrenn jswrenn force-pushed the Gae2a2cdb24c00b662f0909211910d1afe272d793 branch from 807fb77 to 70e46d1 Compare December 17, 2025 18:36
@jswrenn jswrenn force-pushed the G9e7039c715e1ec53e6d860909bb0d618898fd46b branch from ba063c7 to a524fca Compare December 17, 2025 18:36
@jswrenn jswrenn force-pushed the Gae2a2cdb24c00b662f0909211910d1afe272d793 branch from 70e46d1 to 86f1080 Compare December 17, 2025 18:39
@jswrenn jswrenn force-pushed the G9e7039c715e1ec53e6d860909bb0d618898fd46b branch from a524fca to 33f3fb6 Compare December 17, 2025 18:39
@jswrenn jswrenn force-pushed the Gae2a2cdb24c00b662f0909211910d1afe272d793 branch from 86f1080 to ed84c83 Compare December 18, 2025 19:26
@jswrenn jswrenn force-pushed the G9e7039c715e1ec53e6d860909bb0d618898fd46b branch from 33f3fb6 to 345b7d3 Compare December 18, 2025 19:26
@jswrenn jswrenn force-pushed the Gae2a2cdb24c00b662f0909211910d1afe272d793 branch from ed84c83 to d7ed67c Compare December 18, 2025 19:55
@jswrenn jswrenn force-pushed the G9e7039c715e1ec53e6d860909bb0d618898fd46b branch from 345b7d3 to abf9b1c Compare December 18, 2025 19:55
@jswrenn jswrenn force-pushed the Gae2a2cdb24c00b662f0909211910d1afe272d793 branch from d7ed67c to 37e55de Compare December 18, 2025 20:36
@jswrenn jswrenn force-pushed the G9e7039c715e1ec53e6d860909bb0d618898fd46b branch from abf9b1c to dcf49b9 Compare December 18, 2025 20:36
@jswrenn jswrenn force-pushed the Gae2a2cdb24c00b662f0909211910d1afe272d793 branch from 37e55de to c1223ff Compare December 18, 2025 20:41
@jswrenn jswrenn force-pushed the G9e7039c715e1ec53e6d860909bb0d618898fd46b branch 2 times, most recently from 4e3e874 to 898e717 Compare December 20, 2025 17:06
@jswrenn jswrenn force-pushed the Gae2a2cdb24c00b662f0909211910d1afe272d793 branch from c1223ff to 202d8d4 Compare December 20, 2025 17:06
@joshlf joshlf force-pushed the G9e7039c715e1ec53e6d860909bb0d618898fd46b branch 2 times, most recently from e28215f to 122da00 Compare December 20, 2025 19:04
Base automatically changed from G9e7039c715e1ec53e6d860909bb0d618898fd46b to main December 20, 2025 19:41
gherrit-pr-id: Gae2a2cdb24c00b662f0909211910d1afe272d793
@jswrenn jswrenn force-pushed the Gae2a2cdb24c00b662f0909211910d1afe272d793 branch from 202d8d4 to b3ddd2e Compare December 22, 2025 15:16
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.

2 participants