Skip to content

Commit bd138e2

Browse files
committed
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. :)
2 parents d4a881e + f2172ea commit bd138e2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

library/alloc/src/boxed.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@ impl dyn Error + Send {
21832183
let err: Box<dyn Error> = self;
21842184
<dyn Error>::downcast(err).map_err(|s| unsafe {
21852185
// Reapply the `Send` marker.
2186-
mem::transmute::<Box<dyn Error>, Box<dyn Error + Send>>(s)
2186+
Box::from_raw(Box::into_raw(s) as *mut (dyn Error + Send))
21872187
})
21882188
}
21892189
}
@@ -2197,7 +2197,7 @@ impl dyn Error + Send + Sync {
21972197
let err: Box<dyn Error> = self;
21982198
<dyn Error>::downcast(err).map_err(|s| unsafe {
21992199
// Reapply the `Send + Sync` marker.
2200-
mem::transmute::<Box<dyn Error>, Box<dyn Error + Send + Sync>>(s)
2200+
Box::from_raw(Box::into_raw(s) as *mut (dyn Error + Send + Sync))
22012201
})
22022202
}
22032203
}

0 commit comments

Comments
 (0)