Skip to content

Commit

Permalink
Rollup merge of #117266 - RalfJung:cast-not-transmute, r=thomcc
Browse files Browse the repository at this point in the history
replace transmute by raw pointer cast

Now that #113257 is fixed we can finally do this. :)
  • Loading branch information
matthiaskrgr authored Oct 27, 2023
2 parents 3374480 + b3f7f4d commit 2fdac63
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
//
Expand All @@ -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,
})
Expand Down

0 comments on commit 2fdac63

Please sign in to comment.