{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreibxpfsjn7nwi524loaksov3ziu7ayhssyaof4bwkoskzu2bwt2wxa",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mkv5yn56qf52"
},
"path": "/t/bitslice-or-a-sound-way-to-implement-one/24194#post_11",
"publishedAt": "2026-05-02T14:51:01.000Z",
"site": "https://internals.rust-lang.org",
"textContent": "I _think_ we can permit forming two `&mut u1` references to neighboring bits of the same byte in single-threaded scenarios, but I could be missing something. However, if you have something like `([Mutex<()>; 2], UnsafeCell<[u1; 2]>)`, is it sound to concurrently mutate each `u1` value on different threads? I believe the answer to that is _no_ , which makes things… complicated. However, I don’t think it can break existing generic code.\n\nHere’s my attempt:\n\n\n struct DoubleMutex<T: ?Sized> {\n one: Mutex<()>,\n two: Mutex<()>,\n // not possible.\n\n // And `T: Sized` wouldn’t break from `u1`.\n // packed: UnsafeCell<[T; 2]>,\n\n // uses `size_of_val` to pack two `T`s on the heap.\n // However, that function has byte granularity;\n // if `u1: MetaSized`, we’d presumably end up\n // adding 7 bits of padding between the `u1`s here.\n packed2: NonNull<()>,\n\n // other fields used to get `packed2` to work\n …,\n }\n\n\nEdit: wait, doesn’t this imply that `&mut u1: Send` cannot be permitted to hold, so `u1: !Send`?\n\nThat’s a massive pain for a POD type.",
"title": "`BitSlice` or a sound way to implement one"
}