The code that implements the write_bytes method in the impl Bytes<usize> for MockBytesContainer block here relies on undefined behaviour, in particular, creating a &mut reference to data behind a non-mut reference is bad, since it violates the safety contract of non-mut references.
This code happens to have "worked" until current stable Rust / LLVM 15, but starts to exhibit weird failures with future Rust that will use LLVM 16. If this code really needs to rely on "interior mutability", then self.container should probably wrap the backing data in a RefCell or a Mutex to avoid relying on unsafe / undefined behaviour.
The code that implements the
write_bytes
method in theimpl Bytes<usize> for MockBytesContainer
block here relies on undefined behaviour, in particular, creating a&mut
reference to data behind a non-mut
reference is bad, since it violates the safety contract of non-mut
references.This code happens to have "worked" until current stable Rust / LLVM 15, but starts to exhibit weird failures with future Rust that will use LLVM 16. If this code really needs to rely on "interior mutability", then
self.container
should probably wrap the backing data in aRefCell
or aMutex
to avoid relying on unsafe / undefined behaviour.