Rollup merge of #117266 - RalfJung:cast-not-transmute, r=thomcc

replace transmute by raw pointer cast

Now that https://github.com/rust-lang/rust/issues/113257 is fixed we can finally do this. :)
This commit is contained in:
Matthias Krüger 2023-10-27 11:48:07 +02:00 committed by GitHub
commit 2fdac630b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -545,6 +545,13 @@ impl Builder {
scope_data.increment_num_running_threads();
}
let main = Box::new(main);
#[cfg(bootstrap)]
let main =
unsafe { mem::transmute::<Box<dyn FnOnce() + 'a>, Box<dyn FnOnce() + 'static>>(main) };
#[cfg(not(bootstrap))]
let main = unsafe { Box::from_raw(Box::into_raw(main) as *mut (dyn FnOnce() + 'static)) };
Ok(JoinInner {
// SAFETY:
//
@ -559,14 +566,7 @@ impl Builder {
// Similarly, the `sys` implementation must guarantee that no references to the closure
// exist after the thread has terminated, which is signaled by `Thread::join`
// returning.
native: unsafe {
imp::Thread::new(
stack_size,
mem::transmute::<Box<dyn FnOnce() + 'a>, Box<dyn FnOnce() + 'static>>(
Box::new(main),
),
)?
},
native: unsafe { imp::Thread::new(stack_size, main)? },
thread: my_thread,
packet: my_packet,
})