File tree Expand file tree Collapse file tree 2 files changed +6
-19
lines changed
compiler/rustc_interface/src Expand file tree Collapse file tree 2 files changed +6
-19
lines changed Original file line number Diff line number Diff line change 11#![ feature( bool_to_option) ]
22#![ feature( box_patterns) ]
33#![ feature( internal_output_capture) ]
4+ #![ feature( thread_spawn_unchecked) ]
45#![ feature( nll) ]
56#![ feature( once_cell) ]
67#![ recursion_limit = "256" ]
Original file line number Diff line number Diff line change @@ -115,25 +115,11 @@ fn get_stack_size() -> Option<usize> {
115115/// for `'static` bounds.
116116#[ cfg( not( parallel_compiler) ) ]
117117pub fn scoped_thread < F : FnOnce ( ) -> R + Send , R : Send > ( cfg : thread:: Builder , f : F ) -> R {
118- struct Ptr ( * mut ( ) ) ;
119- unsafe impl Send for Ptr { }
120- unsafe impl Sync for Ptr { }
121-
122- let mut f = Some ( f) ;
123- let run = Ptr ( & mut f as * mut _ as * mut ( ) ) ;
124- let mut result = None ;
125- let result_ptr = Ptr ( & mut result as * mut _ as * mut ( ) ) ;
126-
127- let thread = cfg. spawn ( move || {
128- let _ = ( & run, & result_ptr) ;
129- let run = unsafe { ( * ( run. 0 as * mut Option < F > ) ) . take ( ) . unwrap ( ) } ;
130- let result = unsafe { & mut * ( result_ptr. 0 as * mut Option < R > ) } ;
131- * result = Some ( run ( ) ) ;
132- } ) ;
133-
134- match thread. unwrap ( ) . join ( ) {
135- Ok ( ( ) ) => result. unwrap ( ) ,
136- Err ( p) => panic:: resume_unwind ( p) ,
118+ // SAFETY: join() is called immediately, so any closure captures are still
119+ // alive.
120+ match unsafe { cfg. spawn_unchecked ( f) } . unwrap ( ) . join ( ) {
121+ Ok ( v) => v,
122+ Err ( e) => panic:: resume_unwind ( e) ,
137123 }
138124}
139125
You can’t perform that action at this time.
0 commit comments