Skip to content

Commit

Permalink
Use try_with for with implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Jul 12, 2017
1 parent 8b5549d commit a301f84
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/libstd/thread/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a301f84

Please sign in to comment.