Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TransparentWrapper asserts #232

Merged
merged 2 commits into from
Apr 10, 2024
Merged

Update TransparentWrapper asserts #232

merged 2 commits into from
Apr 10, 2024

Conversation

zachs18
Copy link
Contributor

@zachs18 zachs18 commented Apr 1, 2024

  1. Fixed the {wrap/peel}_slice methods asserts: previously they were comparing the layouts of *const Inner and *const Self, which is are always the same when they're both Sized; now they check that Inner and Self have the same layout.
    • This could cause panics for existing users with incorrect TransparentWrapper implementations.
  2. Added asserts to wrap and peel.
    • This could cause panics for existing users with incorrect TransparentWrapper implementations.
  3. Added comments explaining why we compare size of *const Self in {wrap/peel}_{ref/mut/rc/arc/box}.
  4. Moved some of the asserts and safety comments before the unsafe blocks (no semantic change, I just prefer it).

(I was going to also change the assert!s to debug_assert!s, but since the conditions are all const-foldable anyway, the only affect that would have would be hiding UB in release mode, with no benefit for correct implementations, so I left it using assert!)

@Lokathor Lokathor merged commit eeb6e9d into Lokathor:main Apr 10, 2024
14 checks passed
zachs18 added a commit to zachs18/bytemuck that referenced this pull request Jun 6, 2024
* Update TransparentWrapper asserts.

* Update TransparentWrapperAlloc assert comments.
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