same fix for as_mut

This commit is contained in:
Lokathor 2019-09-20 08:20:18 -06:00
parent c7e124e641
commit 427893ab9b

View File

@ -174,11 +174,7 @@ pub fn try_cast_mut<A: Pod, B: Pod>(a: &mut A) -> Result<&mut B, PodCastError> {
if align_of::<B>() > align_of::<A>() && (a as *mut A as usize) % align_of::<B>() != 0 {
Err(PodCastError::TargetAlignmentGreaterAndInputNotAligned)
} else if size_of::<B>() == size_of::<A>() {
Ok(unsafe {
(a as *mut A as *mut B)
.as_mut()
.unwrap_or_else(|| core::hint::unreachable_unchecked())
})
Ok(unsafe { &mut *(a as *mut A as *mut B) })
} else {
Err(PodCastError::SizeMismatch)
}