diff --git a/src/lib.rs b/src/lib.rs index 84515b1837..3ad0d8c823 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3313,10 +3313,10 @@ pub unsafe trait IntoBytes { Self: NoCell, { let start = bytes.len().checked_sub(mem::size_of_val(self))?; - bytes - .get_mut(start..) - .expect("`start` should be in-bounds of `bytes`") - .copy_from_slice(self.as_bytes()); + // get_mut() should never return None here. We use ? rather than + // .unwrap() because in the event the branch is not optimized away, + // returning None is generally lighter-weight than panicing. + bytes.get_mut(start..)?.copy_from_slice(self.as_bytes()); Some(()) }