Skip to content

[derive] Support IntoBytes on homogeneous generic structs#3488

Open
joshlf wants to merge 1 commit into
mainfrom
Gsxxjwwhqbpepd5p73rd6libcy7n44svt
Open

[derive] Support IntoBytes on homogeneous generic structs#3488
joshlf wants to merge 1 commit into
mainfrom
Gsxxjwwhqbpepd5p73rd6libcy7n44svt

Conversation

@joshlf

@joshlf joshlf commented Jul 16, 2026

Copy link
Copy Markdown
Member

Support deriving IntoBytes on unmodified repr(C) structs whose
fields are all T, [T; N], or a final [T] for the same generic type
parameter T.

All such fields have the same alignment, and each field's size is a
multiple of that alignment. Thus, repr(C) introduces neither
inter-field nor trailing padding.

Use an Identity<Type = T> bound to have rustc verify that each field's
element type actually resolves to T. This guards against
macro-generated identifiers which compare equal in the derive but have
different hygiene contexts.


Latest Update: v4 — Compare vs v3

📚 Full Patch History

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

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

Checkout

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

Cherry Pick

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

Pull

git pull origin refs/heads/Gsxxjwwhqbpepd5p73rd6libcy7n44svt

Stacked PRs enabled by GHerrit.

@joshlf
joshlf requested a review from jswrenn July 16, 2026 21:45
@joshlf
joshlf enabled auto-merge July 16, 2026 21:45
@codecov-commenter

codecov-commenter commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.85%. Comparing base (bac77f0) to head (19fa501).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3488   +/-   ##
=======================================
  Coverage   91.85%   91.85%           
=======================================
  Files          20       20           
  Lines        6093     6093           
=======================================
  Hits         5597     5597           
  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.

@joshlf
joshlf force-pushed the Gsxxjwwhqbpepd5p73rd6libcy7n44svt branch 2 times, most recently from 1135bd6 to f22a183 Compare July 16, 2026 23:24

let is_transparent = repr.is_transparent();
let is_c = repr.is_c();
let is_unmodified_c = is_c && repr.get_align().is_none() && repr.get_packed().is_none();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why are you checking for the absence of packed, which can only reduce the presence of padding?

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.

Just being conservative, but you've convinced me to just go all the way. Fixed.

Support deriving `IntoBytes` on unmodified `repr(C)` structs whose
fields are all `T`, `[T; N]`, or a final `[T]` for the same generic type
parameter `T`.

All such fields have the same alignment, and each field's size is a
multiple of that alignment. Thus, `repr(C)` introduces neither
inter-field nor trailing padding.

Use an `Identity<Type = T>` bound to have rustc verify that each field's
element type actually resolves to `T`. This guards against
macro-generated identifiers which compare equal in the derive but have
different hygiene contexts.

gherrit-pr-id: Gsxxjwwhqbpepd5p73rd6libcy7n44svt
@joshlf
joshlf force-pushed the Gsxxjwwhqbpepd5p73rd6libcy7n44svt branch from f22a183 to 19fa501 Compare July 17, 2026 18:07
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.

3 participants