Skip to content

Commit

Permalink
Return without a reference in unix Weak::get()
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Feb 13, 2019
1 parent 70c5af8 commit 33d80bf
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/libstd/sys/unix/weak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@ impl<F> Weak<F> {
}
}

pub fn get(&self) -> Option<&F> {
pub fn get(&self) -> Option<F> {
assert_eq!(mem::size_of::<F>(), mem::size_of::<usize>());
unsafe {
if self.addr.load(Ordering::SeqCst) == 1 {
self.addr.store(fetch(self.name), Ordering::SeqCst);
}
if self.addr.load(Ordering::SeqCst) == 0 {
None
} else {
mem::transmute::<&AtomicUsize, Option<&F>>(&self.addr)
match self.addr.load(Ordering::SeqCst) {
0 => None,
addr => Some(mem::transmute_copy::<usize, F>(&addr)),
}
}
}
Expand Down

0 comments on commit 33d80bf

Please sign in to comment.