File tree 1 file changed +16
-12
lines changed
compiler/rustc_interface/src
1 file changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -136,20 +136,24 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
136
136
f : F ,
137
137
) -> R {
138
138
// 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
+ }
143
144
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 ( ) ;
145
151
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
+ } )
153
157
}
154
158
155
159
/// Creates a new thread and forwards information in thread locals to it.
You can’t perform that action at this time.
0 commit comments