Auto merge of #114799 - RalfJung:less-transmute, r=m-ou-se

avoid transmuting Box when we can just cast raw pointers instead

Always better to avoid a transmute, in particular when the layout assumptions it is making are not clearly documented. :)
This commit is contained in:
bors 2023-08-17 09:09:29 +00:00
commit bd138e2ae1
1 changed files with 2 additions and 2 deletions

View File

@ -2183,7 +2183,7 @@ impl dyn Error + Send {
let err: Box<dyn Error> = self;
<dyn Error>::downcast(err).map_err(|s| unsafe {
// Reapply the `Send` marker.
mem::transmute::<Box<dyn Error>, Box<dyn Error + Send>>(s)
Box::from_raw(Box::into_raw(s) as *mut (dyn Error + Send))
})
}
}
@ -2197,7 +2197,7 @@ impl dyn Error + Send + Sync {
let err: Box<dyn Error> = self;
<dyn Error>::downcast(err).map_err(|s| unsafe {
// Reapply the `Send + Sync` marker.
mem::transmute::<Box<dyn Error>, Box<dyn Error + Send + Sync>>(s)
Box::from_raw(Box::into_raw(s) as *mut (dyn Error + Send + Sync))
})
}
}