about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-10-27 11:48:07 +0200
committerGitHub <noreply@github.com>2023-10-27 11:48:07 +0200
commit2fdac630b4b38c8b2669d5b6071f9b822a2d3729 (patch)
treea1a30e43d27e2a23cb5f5024b8627fada5970a42
parent33744804fe1882ef986c9cc76638fff3b97c593a (diff)
parentb3f7f4dff75e3beaa7b6e60f9e5484f82fff8065 (diff)
downloadrust-2fdac630b4b38c8b2669d5b6071f9b822a2d3729.tar.gz
rust-2fdac630b4b38c8b2669d5b6071f9b822a2d3729.zip
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. :)
-rw-r--r--library/std/src/thread/mod.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs
index 7b26068c294..68ea486933a 100644
--- a/library/std/src/thread/mod.rs
+++ b/library/std/src/thread/mod.rs
@@ -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,
         })