about summary refs log tree commit diff
path: root/src/libstd/thread
diff options
context:
space:
mode:
authorLee Bousfield <ljbousfield@gmail.com>2017-07-12 10:55:39 -0600
committerLee Bousfield <ljbousfield@gmail.com>2017-07-12 10:55:39 -0600
commita301f84b6afc30c58dede5ddd804890f7a6f20a5 (patch)
tree6442534f04d21f009dc4363a00bd4cb2a65fee34 /src/libstd/thread
parent8b5549defb629210a8ffc1af08b3209e084fbfd8 (diff)
downloadrust-a301f84b6afc30c58dede5ddd804890f7a6f20a5.tar.gz
rust-a301f84b6afc30c58dede5ddd804890f7a6f20a5.zip
Use try_with for with implementation
Diffstat (limited to 'src/libstd/thread')
-rw-r--r--src/libstd/thread/local.rs11
1 files changed, 2 insertions, 9 deletions
diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs
index 18979fbbdbe..28e8f72ac64 100644
--- a/src/libstd/thread/local.rs
+++ b/src/libstd/thread/local.rs
@@ -284,15 +284,8 @@ impl<T: 'static> LocalKey<T> {
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn with<F, R>(&'static self, f: F) -> R
                       where F: FnOnce(&T) -> R {
-        unsafe {
-            let slot = (self.inner)();
-            let slot = slot.expect("cannot access a TLS value during or \
-                                    after it is destroyed");
-            f(match *slot.get() {
-                Some(ref inner) => inner,
-                None => self.init(slot),
-            })
-        }
+        self.try_with(f).expect("cannot access a TLS value during or \
+                                 after it is destroyed")
     }
 
     unsafe fn init(&self, slot: &UnsafeCell<Option<T>>) -> &T {