avoid transmuting Box when we can just cast raw pointers instead

This commit is contained in:
Ralf Jung 2023-08-14 10:15:25 +02:00
parent 3071e0aef6
commit f2172ea4e2

View File

@ -2183,7 +2183,7 @@ pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<dyn E
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 @@ pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<Self>
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))
})
}
}