From 1efd9958a35b79841cbf6118fef73a34811dbcfe Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Thu, 23 Jan 2020 19:05:20 +0100 Subject: [PATCH] Assert that the alignment of Shared is appropriate (#362) --- src/bytes.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/bytes.rs b/src/bytes.rs index d8af5b5..35a3c75 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -905,6 +905,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,