Skip to content

Commit a301f84

Browse files
committed
Use try_with for with implementation
1 parent 8b5549d commit a301f84

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

src/libstd/thread/local.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,8 @@ impl<T: 'static> LocalKey<T> {
284284
#[stable(feature = "rust1", since = "1.0.0")]
285285
pub fn with<F, R>(&'static self, f: F) -> R
286286
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-
}
287+
self.try_with(f).expect("cannot access a TLS value during or \
288+
after it is destroyed")
296289
}
297290

298291
unsafe fn init(&self, slot: &UnsafeCell<Option<T>>) -> &T {

0 commit comments

Comments
 (0)