about summary refs log tree commit diff
path: root/compiler/rustc_interface/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-09-25 00:20:28 +0000
committerbors <bors@rust-lang.org>2021-09-25 00:20:28 +0000
commit6867dd2c014a3ebd20948c64671a569c2b7dffc1 (patch)
tree702011a6c30204d7dbdf4b01511707cf930d6716 /compiler/rustc_interface/src
parent043972f152398a7e4c579dd465da42bb52d6da31 (diff)
parent6f31fa58fd0c4c045f4dd71170868750739e1135 (diff)
downloadrust-6867dd2c014a3ebd20948c64671a569c2b7dffc1.tar.gz
rust-6867dd2c014a3ebd20948c64671a569c2b7dffc1.zip
Auto merge of #89230 - workingjubilee:rollup-1swktdq, r=workingjubilee
Rollup of 8 pull requests

Successful merges:

 - #88893 (Add 1.56.0 release notes)
 - #89001 (Be explicit about using Binder::dummy)
 - #89072 (Avoid a couple of Symbol::as_str calls in cg_llvm )
 - #89104 (Simplify scoped_thread)
 - #89208 ([rfc 2229] Drop fully captured upvars in the same order as the regular drop code)
 - #89210 (Add missing time complexities to linked_list.rs)
 - #89217 (Enable "generate-link-to-definition" option on rust tools docs as well)
 - #89221 (Give better error for `macro_rules! name!`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_interface/src')
-rw-r--r--compiler/rustc_interface/src/lib.rs1
-rw-r--r--compiler/rustc_interface/src/util.rs24
2 files changed, 6 insertions, 19 deletions
diff --git a/compiler/rustc_interface/src/lib.rs b/compiler/rustc_interface/src/lib.rs
index c7424b9e2a1..2fc3759968f 100644
--- a/compiler/rustc_interface/src/lib.rs
+++ b/compiler/rustc_interface/src/lib.rs
@@ -1,6 +1,7 @@
 #![feature(bool_to_option)]
 #![feature(box_patterns)]
 #![feature(internal_output_capture)]
+#![feature(thread_spawn_unchecked)]
 #![feature(nll)]
 #![feature(once_cell)]
 #![recursion_limit = "256"]
diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs
index 3d90a6c9345..24975702b87 100644
--- a/compiler/rustc_interface/src/util.rs
+++ b/compiler/rustc_interface/src/util.rs
@@ -115,25 +115,11 @@ fn get_stack_size() -> Option<usize> {
 /// for `'static` bounds.
 #[cfg(not(parallel_compiler))]
 pub fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f: F) -> R {
-    struct Ptr(*mut ());
-    unsafe impl Send for Ptr {}
-    unsafe impl Sync for Ptr {}
-
-    let mut f = Some(f);
-    let run = Ptr(&mut f as *mut _ as *mut ());
-    let mut result = None;
-    let result_ptr = Ptr(&mut result as *mut _ as *mut ());
-
-    let thread = cfg.spawn(move || {
-        let _ = (&run, &result_ptr);
-        let run = unsafe { (*(run.0 as *mut Option<F>)).take().unwrap() };
-        let result = unsafe { &mut *(result_ptr.0 as *mut Option<R>) };
-        *result = Some(run());
-    });
-
-    match thread.unwrap().join() {
-        Ok(()) => result.unwrap(),
-        Err(p) => panic::resume_unwind(p),
+    // SAFETY: join() is called immediately, so any closure captures are still
+    // alive.
+    match unsafe { cfg.spawn_unchecked(f) }.unwrap().join() {
+        Ok(v) => v,
+        Err(e) => panic::resume_unwind(e),
     }
 }