[Merged by Bors] - Respect alignment for zero-sized types stored in the world#6618
[Merged by Bors] - Respect alignment for zero-sized types stored in the world#6618joseph-gio wants to merge 4 commits intobevyengine:mainfrom
Conversation
|
Just so I understand the context more: why would you want to mess with the alignment of ZSTs? Definitely agree that this is needed, but I'm trying to piece this together better. |
I'm not aware of any actual use cases for this kind of alignment fiddling. This PR is about correctness more than anything -- I would be surprised if this issue caused any problems in practice. |
|
Merging: either we make a 0.9.1 release and it's in there, or we don't and there's no harm done by merging early. bors r+ |
# Objective Fixes #6615. `BlobVec` does not respect alignment for zero-sized types, which results in UB whenever a ZST with alignment other than 1 is used in the world. ## Solution Add the fn `bevy_ptr::dangling_with_align`. --- ## Changelog + Added the function `dangling_with_align` to `bevy_ptr`, which creates a well-aligned dangling pointer to a type whose alignment is not known at compile time.
# Objective Fixes #6615. `BlobVec` does not respect alignment for zero-sized types, which results in UB whenever a ZST with alignment other than 1 is used in the world. ## Solution Add the fn `bevy_ptr::dangling_with_align`. --- ## Changelog + Added the function `dangling_with_align` to `bevy_ptr`, which creates a well-aligned dangling pointer to a type whose alignment is not known at compile time.
…e#6618) # Objective Fixes bevyengine#6615. `BlobVec` does not respect alignment for zero-sized types, which results in UB whenever a ZST with alignment other than 1 is used in the world. ## Solution Add the fn `bevy_ptr::dangling_with_align`. --- ## Changelog + Added the function `dangling_with_align` to `bevy_ptr`, which creates a well-aligned dangling pointer to a type whose alignment is not known at compile time.
|
So apparently this actually can matter in practice: https://doc.rust-lang.org/reference/type-layout.html According to this, |
Objective
Fixes #6615.
BlobVecdoes not respect alignment for zero-sized types, which results in UB whenever a ZST with alignment other than 1 is used in the world.Solution
Add the fn
bevy_ptr::dangling_with_align.Changelog
dangling_with_aligntobevy_ptr, which creates a well-aligned dangling pointer to a type whose alignment is not known at compile time.