File tree 2 files changed +6
-19
lines changed
compiler/rustc_interface/src
2 files changed +6
-19
lines changed Original file line number Diff line number Diff line change 1
1
#![ feature( bool_to_option) ]
2
2
#![ feature( box_patterns) ]
3
3
#![ feature( internal_output_capture) ]
4
+ #![ feature( thread_spawn_unchecked) ]
4
5
#![ feature( nll) ]
5
6
#![ feature( once_cell) ]
6
7
#![ recursion_limit = "256" ]
Original file line number Diff line number Diff line change @@ -115,25 +115,11 @@ fn get_stack_size() -> Option<usize> {
115
115
/// for `'static` bounds.
116
116
#[ cfg( not( parallel_compiler) ) ]
117
117
pub 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) ,
137
123
}
138
124
}
139
125
You can’t perform that action at this time.
0 commit comments