mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-07 00:00:13 +02:00
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:
+6
-1
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user