From a301f84b6afc30c58dede5ddd804890f7a6f20a5 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Wed, 12 Jul 2017 10:55:39 -0600 Subject: Use try_with for with implementation --- src/libstd/thread/local.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'src/libstd') 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 LocalKey { #[stable(feature = "rust1", since = "1.0.0")] pub fn with(&'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>) -> &T { -- cgit 1.4.1-3-g733a5