Skip to content

Commit d156a90

Browse files
committed
Inline and remove scoped_thread.
It has a single call site, and removing it slightly improves the confusing tangle of nested closures present at startup.
1 parent c461f3a commit d156a90

File tree

1 file changed

+9
-15
lines changed
  • compiler/rustc_interface/src

1 file changed

+9
-15
lines changed

compiler/rustc_interface/src/util.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,33 +132,27 @@ fn get_stack_size() -> Option<usize> {
132132
env::var_os("RUST_MIN_STACK").is_none().then_some(STACK_SIZE)
133133
}
134134

135-
/// Like a `thread::Builder::spawn` followed by a `join()`, but avoids the need
136-
/// for `'static` bounds.
137-
#[cfg(not(parallel_compiler))]
138-
fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f: F) -> R {
139-
// SAFETY: join() is called immediately, so any closure captures are still
140-
// alive.
141-
match unsafe { cfg.spawn_unchecked(f) }.unwrap().join() {
142-
Ok(v) => v,
143-
Err(e) => panic::resume_unwind(e),
144-
}
145-
}
146-
147135
#[cfg(not(parallel_compiler))]
148136
pub fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
149137
edition: Edition,
150138
_threads: usize,
151139
f: F,
152140
) -> R {
141+
// The thread pool is a single thread in the non-parallel compiler.
153142
let mut cfg = thread::Builder::new().name("rustc".to_string());
154-
155143
if let Some(size) = get_stack_size() {
156144
cfg = cfg.stack_size(size);
157145
}
158146

159-
let main_handler = move || rustc_span::create_session_globals_then(edition, f);
147+
let f = move || rustc_span::create_session_globals_then(edition, f);
160148

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

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

0 commit comments

Comments
 (0)