Skip to content

Commit 63db9e5

Browse files
committed
Replace a spawn_unchecked with spawn_scoped.
1 parent ec409f9 commit 63db9e5

File tree

1 file changed

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

1 file changed

+16
-12
lines changed

Diff for: compiler/rustc_interface/src/util.rs

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

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

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

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

0 commit comments

Comments
 (0)