Skip to content

[derive] Use fresh ASCII ___ZcField_ prefix for field markers - #3930

Open
joshlf wants to merge 1 commit into
mainfrom
G2v47f6fsyy7ghpeb7rdbrpvrk3esc4u6
Open

joshlf wants to merge 1 commit into
mainfrom
G2v47f6fsyy7ghpeb7rdbrpvrk3esc4u6

Conversation

@joshlf

@joshlf joshlf commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

In Unicode 18 (picked up by rustc in rust-lang/rust#165289 starting in
nightly-2026-11-18), UTS #39 reclassified ẕ (U+1E95) from
IdentifierType::Recommended to IdentifierType::Uncommon_Use. Because
derive_projection_struct_union constructed enum ẕ<field> {} with
ident.span(), rustc recorded the identifier under the caller's span and
emitted uncommon_codepoints warnings (and rejected crates with
#![deny(non_ascii_idents)]; neither lint can be suppressed at item
scope because uncommon_codepoints and non_ascii_idents are
crate_level_only).

Additionally, using a fixed marker prefix without checking DeriveInput
allowed a colliding generic type parameter on Self to shadow the
generated private marker enum inside HasField and ProjectField,
substituting the caller-chosen type argument as Field and exposing
private fields to external safe Ptr::project callers.

Replace ẕ with a fresh ASCII prefix (ctx.fresh_prefix("___ZcField_"))
at Span::mixed_site(), scope each field's marker enum to its own
const block, and freshen ___ZcAliasing and ___ZcAlignment in
project.rs via ctx.fresh_ident. Compute fresh suffixes in a single
linear pass over input tokens, and mix in a deterministic 128-bit token
hash whenever DeriveInput contains ! as a best-effort collision
mitigation when unexpanded macros are present (complete item-namespace
isolation of non-pub markers from replayed type-position macros is not
possible on stable Rust MSRV 1.56 without unstable Span::def_site(),
because E0446 rejects projecting private field types through a pub
helper trait on a pub Self without a non-pub type in the impl
header, fn-local derives preclude super:: module escapes, and output
must remain deterministic for reproducible builds).

Add unit, snapshot, integration, and MSRV/stable/nightly UI regression
tests covering identifier lints (uncommon_codepoints,
non_ascii_idents, confusable_idents, mixed_script_confusables),
outer-type and self-name collisions, unexpanded type-macro collisions,
linear-time long underscore runs, cascading generic-parameter collisions,
and private-field encapsulation.

Closes #2880
Closes #3929

Agent-authored-by: AI agent acting on joshlf's behalf


Latest Update: v3 — Compare vs v2

📚 Full Patch History

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

Version v2 v1 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/G2v47f6fsyy7ghpeb7rdbrpvrk3esc4u6 && git checkout -b pr-G2v47f6fsyy7ghpeb7rdbrpvrk3esc4u6 FETCH_HEAD

Checkout

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

Cherry Pick

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

Pull

git pull origin refs/heads/G2v47f6fsyy7ghpeb7rdbrpvrk3esc4u6

Stacked PRs enabled by GHerrit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T03:49:58.366081Z 362ae27 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.

@codecov-commenter

codecov-commenter commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.99%. Comparing base (ec133ce) to head (362ae27).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3930   +/-   ##
=======================================
  Coverage   92.99%   92.99%           
=======================================
  Files          16       16           
  Lines        2469     2469           
=======================================
  Hits         2296     2296           
  Misses        173      173           

☔ 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 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: 11156a43f3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread zerocopy/zerocopy-derive/src/util.rs Resolved
@joshlf
joshlf requested a review from jswrenn November 19, 2026 03:00
@joshlf

joshlf commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@codex review

@joshlf
joshlf force-pushed the G2v47f6fsyy7ghpeb7rdbrpvrk3esc4u6 branch from 11156a4 to 74294e7 Compare November 19, 2026 03:19

@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: 74294e768a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread zerocopy/zerocopy-derive/src/util.rs Resolved
In Unicode 18 (picked up by rustc in rust-lang/rust#165289 starting in
nightly-2026-11-18), UTS #39 reclassified `ẕ` (U+1E95) from
`IdentifierType::Recommended` to `IdentifierType::Uncommon_Use`. Because
`derive_projection_struct_union` constructed `enum ẕ<field> {}` with
`ident.span()`, rustc recorded the identifier under the caller's span and
emitted `uncommon_codepoints` warnings (and rejected crates with
`#![deny(non_ascii_idents)]`; neither lint can be suppressed at item
scope because `uncommon_codepoints` and `non_ascii_idents` are
`crate_level_only`).

Additionally, using a fixed marker prefix without checking `DeriveInput`
allowed a colliding generic type parameter on `Self` to shadow the
generated private marker enum inside `HasField` and `ProjectField`,
substituting the caller-chosen type argument as `Field` and exposing
private fields to external safe `Ptr::project` callers.

Replace `ẕ` with a fresh ASCII prefix (`ctx.fresh_prefix("___ZcField_")`)
at `Span::mixed_site()`, scope each field's marker enum to its own
`const` block, and freshen `___ZcAliasing` and `___ZcAlignment` in
`project.rs` via `ctx.fresh_ident`. Compute fresh suffixes in a single
linear pass over input tokens, and mix in a deterministic 128-bit token
hash whenever `DeriveInput` contains `!` as a best-effort collision
mitigation when unexpanded macros are present (complete item-namespace
isolation of non-`pub` markers from replayed type-position macros is not
possible on stable Rust MSRV 1.56 without unstable `Span::def_site()`,
because `E0446` rejects projecting private field types through a `pub`
helper trait on a `pub` `Self` without a non-`pub` type in the `impl`
header, `fn`-local derives preclude `super::` module escapes, and output
must remain deterministic for reproducible builds).

Add unit, snapshot, integration, and MSRV/stable/nightly UI regression
tests covering identifier lints (`uncommon_codepoints`,
`non_ascii_idents`, `confusable_idents`, `mixed_script_confusables`),
outer-type and self-name collisions, unexpanded type-macro collisions,
linear-time long underscore runs, cascading generic-parameter collisions,
and private-field encapsulation.

Closes #2880
Closes #3929

gherrit-pr-id: G2v47f6fsyy7ghpeb7rdbrpvrk3esc4u6
Agent-authored-by: AI agent acting on joshlf's behalf
@joshlf
joshlf force-pushed the G2v47f6fsyy7ghpeb7rdbrpvrk3esc4u6 branch from 74294e7 to 362ae27 Compare November 19, 2026 03:47
@joshlf

joshlf commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 362ae27763

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

This branch has not been deployed

No deployments
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.

Derives trigger uncommon_codepoints on nightly Zerocopy 0.8.32 breaks combined with deny(non_ascii_idents)

2 participants