Skip to content

Reject derive inputs that capture generated helpers - #3635

Open
joshlf wants to merge 1 commit into
Gifjr6pbpu4fh6t7qbzuuqczj3odny3ckfrom
Gkiogbp7b2w7nxwx27s7vk5wesojtk7bn
Open

Reject derive inputs that capture generated helpers#3635
joshlf wants to merge 1 commit into
Gifjr6pbpu4fh6t7qbzuuqczj3odny3ckfrom
Gkiogbp7b2w7nxwx27s7vk5wesojtk7bn

Conversation

@joshlf

@joshlf joshlf commented Sep 5, 2026

Copy link
Copy Markdown
Member

Derive expansions copy user syntax into generated scopes and refer to helper
items by unqualified names. Reject uninspectable syntax, contextual Self,
and identifiers that could change the meaning of copied fields or generated
safety checks.

Pin the Syn grammar used by this validation and add cross-toolchain
regressions for helper capture, copied macros, qualified paths, and enum tag
validation.

Closes #3633

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.


Latest Update: v7 — Compare vs v6

📚 Full Patch History

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

Version v6 v5 v4 v3 v2 v1 Base
v7 vs v6 vs v5 vs v4 vs v3 vs v2 vs v1 vs Base
v6 vs v5 vs v4 vs v3 vs v2 vs v1 vs Base
v5 vs v4 vs v3 vs v2 vs v1 vs Base
v4 vs v3 vs v2 vs v1 vs Base
v3 vs v2 vs v1 vs Base
v2 vs v1 vs Base
v1 vs Base
⬇️ Download this PR

Branch

git fetch origin refs/heads/Gkiogbp7b2w7nxwx27s7vk5wesojtk7bn && git checkout -b pr-Gkiogbp7b2w7nxwx27s7vk5wesojtk7bn FETCH_HEAD

Checkout

git fetch origin refs/heads/Gkiogbp7b2w7nxwx27s7vk5wesojtk7bn && git checkout FETCH_HEAD

Cherry Pick

git fetch origin refs/heads/Gkiogbp7b2w7nxwx27s7vk5wesojtk7bn && git cherry-pick FETCH_HEAD

Pull

git pull origin refs/heads/Gkiogbp7b2w7nxwx27s7vk5wesojtk7bn

Stacked PRs enabled by GHerrit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-09T05:29:40.062734Z 2b77ff6 Manual request
🔒 Security Review Completed 2026-09-06T17:33:52.481673Z 9ebc60b Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@joshlf

joshlf commented Sep 5, 2026

Copy link
Copy Markdown
Member Author

@codex review

@codecov-commenter

codecov-commenter commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.86%. Comparing base (65f60cb) to head (2b77ff6).

Additional details and impacted files
@@                        Coverage Diff                         @@
##           Gifjr6pbpu4fh6t7qbzuuqczj3odny3ck    #3635   +/-   ##
==================================================================
  Coverage                              91.86%   91.86%           
==================================================================
  Files                                     20       20           
  Lines                                   6097     6097           
==================================================================
  Hits                                    5601     5601           
  Misses                                   496      496           

☔ View full report in Codecov by Harness.
📢 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: e6bf549325

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@joshlf
joshlf force-pushed the Gifjr6pbpu4fh6t7qbzuuqczj3odny3ck branch from 0724207 to ac19a3c Compare September 6, 2026 16:32
@joshlf
joshlf force-pushed the Gkiogbp7b2w7nxwx27s7vk5wesojtk7bn branch from e6bf549 to dd0d485 Compare September 6, 2026 16:32
@joshlf

joshlf commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

@codex review

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd0d485d95

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread zerocopy/zerocopy-derive/src/util.rs
@joshlf
joshlf force-pushed the Gifjr6pbpu4fh6t7qbzuuqczj3odny3ck branch from ac19a3c to 219b88e Compare September 6, 2026 16:47
@joshlf
joshlf force-pushed the Gkiogbp7b2w7nxwx27s7vk5wesojtk7bn branch from dd0d485 to 4de13f3 Compare September 6, 2026 16:49
@joshlf

joshlf commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

@codex review

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 4de13f39cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@joshlf
joshlf force-pushed the Gkiogbp7b2w7nxwx27s7vk5wesojtk7bn branch from 4de13f3 to 9ebc60b Compare September 6, 2026 17:25
@joshlf

joshlf commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

@codex review

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 9ebc60bb63

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 9ebc60bb63

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

#[doc(hidden)] // `#[macro_export]` bypasses this module's `#[doc(hidden)]`.
#[macro_export]
macro_rules! enum_padding {
(@tag_size, $t:ty, $_align:expr, $packed:expr, $disc_size:expr, $([$($ts:ty),*]),*) => {{

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Update the documentation on this macro based on this new branch?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated. The enum_padding! documentation now describes the @tag_size branch, its tag-size expression, and why that expression is evaluated in a lexical scope separate from copied field-type tokens. The generated-side PaddingCheck::Enum documentation was updated consistently. The rebased head also regenerates the affected UI expectations and passes the derive/UI/codegen tests and full pre-push hook.

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@joshlf
joshlf force-pushed the Gifjr6pbpu4fh6t7qbzuuqczj3odny3ck branch from 219b88e to 65f60cb Compare September 9, 2026 03:48
@joshlf
joshlf force-pushed the Gkiogbp7b2w7nxwx27s7vk5wesojtk7bn branch from 9ebc60b to 77afe3a Compare September 9, 2026 03:48
@joshlf

joshlf commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

@codex review

Please review exact head 77afe3aa863b4d65b828953083a6e096110049e1.

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 77afe3aa86

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

reject_uninspectable_field_types(&ctx.ast.data, derive_name)?;

let reserved = match &ctx.ast.data {
Data::Struct(_) | Data::Union(_) => &["___Zc", "ẕ"][..],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reserve the method generic only for nontrivial validators

For a non-generic struct or union derived with FromBytes and on_error = "fail", try_gen_trivial_is_bit_valid emits a validator that references only Self, so user field syntax is never placed inside the scope of ___ZcAlignment; the other field-type copies are in impl-level bounds or associated types outside that method generic. Consequently, a previously valid declaration such as type ___ZcAlignment = u8; #[derive(FromBytes)] struct Packet(___ZcAlignment); is now rejected even though no capture is possible. Apply the ___Zc reservation only when the nontrivial validator actually copies user syntax into that method scope.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

Addressed on exact head 0353a20f43189f535dca715da92fa4848672bd89. The reservation now follows the exact try_gen_trivial_is_bit_valid branch: nongeneric, fail-on-error FromBytes structs, unions, and enums may use ___Zc* names because their validator body mentions only Self. Direct TryFromBytes, FromZeros, generic or skip-mode FromBytes, and generated field-marker ẕ* cases remain rejected. The positive struct/union regression and the compact negative matrix pass on MSRV, stable, and nightly; the repository pre-push hook also passes.

@joshlf
joshlf force-pushed the Gkiogbp7b2w7nxwx27s7vk5wesojtk7bn branch from 77afe3a to 0353a20 Compare September 9, 2026 04:31
@joshlf

joshlf commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

@codex review

Please review exact head 0353a20f43189f535dca715da92fa4848672bd89. The prior finding about over-reserving ___ZcAlignment is addressed, with positive and negative cross-toolchain regressions.

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0353a20f43

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread zerocopy/zerocopy-derive/src/util.rs Outdated

// The derive target is referenced unqualified inside generated helper
// scopes, so its name must not be capturable either.
finder.record(&ctx.ast.ident);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid reserving ___Zc on struct and union names

For a struct or union using the nontrivial validator, this records the derive target itself against the ___Zc method-generic prefix, so a valid declaration such as #[derive(TryFromBytes)] struct ___ZcPacket(bool); is newly rejected. The target name is only used in generated impl headers and field-marker helpers outside is_bit_valid; the validator method refers to it through Self, so ___ZcAlignment cannot capture it. Restrict target-name scanning for this prefix to enum paths that actually copy the target name into the validator scope.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

Addressed on exact head 2b77ff6165d6414c74175ff98fce9b9aff428a62. Target-name scanning now has its own generated-prefix set, separate from copied generics and field types. Struct and union validators refer to the target as Self, so targets named ___Zc* are accepted across direct TryFromBytes, FromZeros, generic FromBytes, and skip-on-error FromBytes; copied syntax still rejects actual method-generic capture. Nonempty field helpers continue to reserve ẕ* targets, zero-field structs reserve no nonexistent field-helper namespace, and full enum validators retain all required target prefixes. Positive and true-collision regressions pass on MSRV, stable, and nightly, and the repository pre-push hook passes.

Derive expansions copy user syntax into generated scopes and refer to helper
items by unqualified names. Reject uninspectable syntax, contextual `Self`,
and identifiers that could change the meaning of copied fields or generated
safety checks.

Pin the Syn grammar used by this validation and add cross-toolchain
regressions for helper capture, copied macros, qualified paths, and enum tag
validation.

Closes #3633

*Authored by an AI agent acting on Josh Liebow-Feeser's behalf.*

gherrit-pr-id: Gkiogbp7b2w7nxwx27s7vk5wesojtk7bn
@joshlf
joshlf force-pushed the Gkiogbp7b2w7nxwx27s7vk5wesojtk7bn branch from 0353a20 to 2b77ff6 Compare September 9, 2026 05:23
@joshlf

joshlf commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@codex review

Please review exact head 2b77ff6165d6414c74175ff98fce9b9aff428a62. The target-name reservation finding is addressed with separate copied-syntax and target-prefix policies plus cross-toolchain regressions.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 2b77ff6165

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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