We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8b5549d commit a301f84Copy full SHA for a301f84
src/libstd/thread/local.rs
@@ -284,15 +284,8 @@ impl<T: 'static> LocalKey<T> {
284
#[stable(feature = "rust1", since = "1.0.0")]
285
pub fn with<F, R>(&'static self, f: F) -> R
286
where F: FnOnce(&T) -> R {
287
- unsafe {
288
- let slot = (self.inner)();
289
- let slot = slot.expect("cannot access a TLS value during or \
290
- after it is destroyed");
291
- f(match *slot.get() {
292
- Some(ref inner) => inner,
293
- None => self.init(slot),
294
- })
295
- }
+ self.try_with(f).expect("cannot access a TLS value during or \
+ after it is destroyed")
296
}
297
298
unsafe fn init(&self, slot: &UnsafeCell<Option<T>>) -> &T {
0 commit comments