-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.T-libs-apiRelevant to the library API team, which will review and decide on the RFC.Relevant to the library API team, which will review and decide on the RFC.
Description
This function is a terror. It is full of undefined behavior, even more than it's sister, transmute
. The only uses of this function are either Undefined Behavior, are transmute
s, except that they didn't try, or are just transmute
s in a generic context.
This is unfortunate. I think we should make this function either much more useful, or deprecate it and get rid of the undefined behavior.
Changing the definition to:
unsafe fn transmute_copy<T: ?Sized, U>(t: &T) -> U {
let u: U = std::mem::uninitialized();
std::ptr::copy_nonoverlapping(t as *const t as *const u8, &mut u as *mut u as *mut u8
std::mem::size_of::<U>());
u
}
would allow us to pull types from byte arrays, for example, without having to do this all by hand.
Otherwise, it should be deprecated, because it isn't really useful enough, and leads to far too many issues; it's only stable because transmute
was unstable at the time.
mark-i-m and bkda
Metadata
Metadata
Assignees
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.T-libs-apiRelevant to the library API team, which will review and decide on the RFC.Relevant to the library API team, which will review and decide on the RFC.