[derive] Support IntoBytes on homogeneous generic structs#3488
Open
joshlf wants to merge 1 commit into
Open
Conversation
joshlf
enabled auto-merge
July 16, 2026 21:45
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
joshlf
force-pushed
the
Gsxxjwwhqbpepd5p73rd6libcy7n44svt
branch
2 times, most recently
from
July 16, 2026 23:24
1135bd6 to
f22a183
Compare
jswrenn
reviewed
Jul 17, 2026
|
|
||
| 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(); |
Collaborator
There was a problem hiding this comment.
Why are you checking for the absence of packed, which can only reduce the presence of padding?
Member
Author
There was a problem hiding this comment.
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
force-pushed
the
Gsxxjwwhqbpepd5p73rd6libcy7n44svt
branch
from
July 17, 2026 18:07
f22a183 to
19fa501
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Support deriving
IntoByteson unmodifiedrepr(C)structs whosefields are all
T,[T; N], or a final[T]for the same generic typeparameter
T.All such fields have the same alignment, and each field's size is a
multiple of that alignment. Thus,
repr(C)introduces neitherinter-field nor trailing padding.
Use an
Identity<Type = T>bound to have rustc verify that each field'selement type actually resolves to
T. This guards againstmacro-generated identifiers which compare equal in the derive but have
different hygiene contexts.
IntoByteson homogeneous generic structs #3488Latest Update: v4 — Compare vs v3
📚 Full Patch History
Links show the diff between the row version and the column version.
⬇️ Download this PR
Branch
git fetch origin refs/heads/Gsxxjwwhqbpepd5p73rd6libcy7n44svt && git checkout -b pr-Gsxxjwwhqbpepd5p73rd6libcy7n44svt FETCH_HEADCheckout
git fetch origin refs/heads/Gsxxjwwhqbpepd5p73rd6libcy7n44svt && git checkout FETCH_HEADCherry Pick
git fetch origin refs/heads/Gsxxjwwhqbpepd5p73rd6libcy7n44svt && git cherry-pick FETCH_HEADPull
Stacked PRs enabled by GHerrit.