Skip to content

Commit 1f0463a

Browse files
committed
Replace a spawn_unchecked with spawn_scoped.
1 parent 8067016 commit 1f0463a

File tree

1 file changed

+16
-12
lines changed
  • compiler/rustc_interface/src

1 file changed

+16
-12
lines changed

compiler/rustc_interface/src/util.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,24 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
138138
f: F,
139139
) -> R {
140140
// The thread pool is a single thread in the non-parallel compiler.
141-
let mut cfg = thread::Builder::new().name("rustc".to_string());
142-
if let Some(size) = get_stack_size() {
143-
cfg = cfg.stack_size(size);
144-
}
141+
thread::scope(|s| {
142+
let mut builder = thread::Builder::new().name("rustc".to_string());
143+
if let Some(size) = get_stack_size() {
144+
builder = builder.stack_size(size);
145+
}
145146

146-
let f = move || rustc_span::create_session_globals_then(edition, f);
147+
// `unwrap` is ok here because `spawn_scoped` only panics if the thread
148+
// name contains null bytes.
149+
let r = builder
150+
.spawn_scoped(s, move || rustc_span::create_session_globals_then(edition, f))
151+
.unwrap()
152+
.join();
147153

148-
// This avoids the need for `'static` bounds.
149-
//
150-
// SAFETY: join() is called immediately, so any closure captures are still alive.
151-
match unsafe { cfg.spawn_unchecked(f) }.unwrap().join() {
152-
Ok(v) => v,
153-
Err(e) => panic::resume_unwind(e),
154-
}
154+
match r {
155+
Ok(v) => v,
156+
Err(e) => panic::resume_unwind(e),
157+
}
158+
})
155159
}
156160

157161
/// Creates a new thread and forwards information in thread locals to it.

0 commit comments

Comments
 (0)