Skip to content

Commit 134e9d3

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 2a62c92 commit 134e9d3

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
@@ -130,33 +130,27 @@ fn get_stack_size() -> Option<usize> {
130130
env::var_os("RUST_MIN_STACK").is_none().then_some(STACK_SIZE)
131131
}
132132

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

157-
let main_handler = move || rustc_span::create_session_globals_then(edition, f);
145+
let f = move || rustc_span::create_session_globals_then(edition, f);
158146

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

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

0 commit comments

Comments
 (0)