about summary refs log tree commit diff
path: root/compiler/rustc_interface/src
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2022-10-08 07:43:15 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2022-10-19 08:09:40 +1100
commit63db9e540c4d358c5a0e63423fc16fa9a7979155 (patch)
tree7718c1dc44f6cfddaf5bc063a8383854fe925ec2 /compiler/rustc_interface/src
parentec409f95bf52c5891084e309fed91fa9b6ce10b4 (diff)
downloadrust-63db9e540c4d358c5a0e63423fc16fa9a7979155.tar.gz
rust-63db9e540c4d358c5a0e63423fc16fa9a7979155.zip
Replace a `spawn_unchecked` with `spawn_scoped`.
Diffstat (limited to 'compiler/rustc_interface/src')
-rw-r--r--compiler/rustc_interface/src/util.rs28
1 files changed, 16 insertions, 12 deletions
diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs
index afc43745b18..6d0fffc152c 100644
--- a/compiler/rustc_interface/src/util.rs
+++ b/compiler/rustc_interface/src/util.rs
@@ -136,20 +136,24 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
     f: F,
 ) -> R {
     // The thread pool is a single thread in the non-parallel compiler.
-    let mut cfg = thread::Builder::new().name("rustc".to_string());
-    if let Some(size) = get_stack_size() {
-        cfg = cfg.stack_size(size);
-    }
+    thread::scope(|s| {
+        let mut builder = thread::Builder::new().name("rustc".to_string());
+        if let Some(size) = get_stack_size() {
+            builder = builder.stack_size(size);
+        }
 
-    let f = move || rustc_span::create_session_globals_then(edition, f);
+        // `unwrap` is ok here because `spawn_scoped` only panics if the thread
+        // name contains null bytes.
+        let r = builder
+            .spawn_scoped(s, move || rustc_span::create_session_globals_then(edition, f))
+            .unwrap()
+            .join();
 
-    // This avoids the need for `'static` bounds.
-    //
-    // 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),
-    }
+        match r {
+            Ok(v) => v,
+            Err(e) => panic::resume_unwind(e),
+        }
+    })
 }
 
 /// Creates a new thread and forwards information in thread locals to it.