File tree Expand file tree Collapse file tree 1 file changed +16
-12
lines changed
compiler/rustc_interface/src Expand file tree Collapse file tree 1 file changed +16
-12
lines changed Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments