From d750543f43715fbe1d15f35294c230f289af8531 Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Tue, 21 Jan 2020 13:04:40 +0100 Subject: [PATCH] Assert that the alignment of Shared is appropriate --- src/bytes.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/bytes.rs b/src/bytes.rs index 93ab84bd4..ed8cbeb39 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -897,6 +897,12 @@ struct Shared { ref_cnt: AtomicUsize, } +// Assert that the alignment of `Shared` is divisible by 2. +// 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::() % 2] = []; // Assert that the alignment of `Shared` is divisible by 2. + static SHARED_VTABLE: Vtable = Vtable { clone: shared_clone, drop: shared_drop,