diff --git a/src/bytes_mut.rs b/src/bytes_mut.rs index 6216fcc76..0ea0272c5 100644 --- a/src/bytes_mut.rs +++ b/src/bytes_mut.rs @@ -481,15 +481,13 @@ impl BytesMut { self.reserve(additional); let dst = self.spare_capacity_mut().as_mut_ptr(); - unsafe { - // SAFETY: `spare_capacity_mut` returns a valid, properly aligned pointer and we've - // reserved enough space to write `additional` bytes. - ptr::write_bytes(dst, value, additional); + // SAFETY: `spare_capacity_mut` returns a valid, properly aligned pointer and we've + // reserved enough space to write `additional` bytes. + unsafe { ptr::write_bytes(dst, value, additional) }; - // SAFETY: There are at least `new_len` initialized bytes in the buffer so no - // uninitialized bytes are being exposed. - self.set_len(new_len); - } + // SAFETY: There are at least `new_len` initialized bytes in the buffer so no + // uninitialized bytes are being exposed. + unsafe { self.set_len(new_len) }; } /// Sets the length of the buffer.