Simplify shared alignment assertions (#841)

Replace array-underflow checks with const assert expressions.
Add diagnostics that explain the pointer-tagging alignment invariant.

Signed-off-by: bestgopher <[email protected]>
This commit is contained in:
bestgopher
2026-07-14 09:45:41 +02:00
committed by GitHub
parent 76c0fbb54e
commit 002df10b8c
2 changed files with 12 additions and 2 deletions
+6 -1
View File
@@ -1348,7 +1348,12 @@ impl Drop for Shared {
// This is a necessary invariant since we depend on allocating `Shared` a
// shared object to implicitly carry the `KIND_ARC` flag in its pointer.
// This flag is set when the LSB is 0.
const _: [(); 0 - mem::align_of::<Shared>() % 2] = []; // Assert that the alignment of `Shared` is divisible by 2.
const _: () = {
assert!(
mem::align_of::<Shared>() % 2 == 0,
"Shared alignment must be divisible by 2 for pointer tagging"
);
};
static SHARED_VTABLE: Vtable = Vtable {
clone: shared_clone,
+6 -1
View File
@@ -92,7 +92,12 @@ impl Shared {
// This is a necessary invariant since we depend on allocating `Shared` a
// shared object to implicitly carry the `KIND_ARC` flag in its pointer.
// This flag is set when the LSB is 0.
const _: [(); 0 - mem::align_of::<Shared>() % 2] = []; // Assert that the alignment of `Shared` is divisible by 2.
const _: () = {
assert!(
mem::align_of::<Shared>() % 2 == 0,
"Shared alignment must be divisible by 2 for pointer tagging"
);
};
// Buffer storage strategy flags.
const KIND_ARC: usize = 0b0;