File tree 1 file changed +12
-10
lines changed
1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -281,10 +281,9 @@ impl<T: 'static> LocalKey<T> {
281
281
where
282
282
F : FnOnce ( & T ) -> R ,
283
283
{
284
- unsafe {
285
- let thread_local = ( self . inner ) ( None ) . ok_or ( AccessError ) ?;
286
- Ok ( f ( thread_local) )
287
- }
284
+ // SAFETY: `inner` is safe to call within the lifetime of the thread
285
+ let thread_local = unsafe { ( self . inner ) ( None ) . ok_or ( AccessError ) ? } ;
286
+ Ok ( f ( thread_local) )
288
287
}
289
288
290
289
/// Acquires a reference to the value in this TLS key, initializing it with
@@ -303,14 +302,17 @@ impl<T: 'static> LocalKey<T> {
303
302
where
304
303
F : FnOnce ( Option < T > , & T ) -> R ,
305
304
{
306
- unsafe {
307
- let mut init = Some ( init) ;
308
- let reference = ( self . inner ) ( Some ( & mut init) ) . expect (
305
+ let mut init = Some ( init) ;
306
+
307
+ // SAFETY: `inner` is safe to call within the lifetime of the thread
308
+ let reference = unsafe {
309
+ ( self . inner ) ( Some ( & mut init) ) . expect (
309
310
"cannot access a Thread Local Storage value \
310
311
during or after destruction",
311
- ) ;
312
- f ( init, reference)
313
- }
312
+ )
313
+ } ;
314
+
315
+ f ( init, reference)
314
316
}
315
317
}
316
318
You can’t perform that action at this time.
0 commit comments