Skip to content

Commit 9c753ea

Browse files
committedJan 28, 2024
Less unsafe with array_methods
Now that `array::each_mut` has stabilized (rust-lang/rust#76118), we'll be able to get rid of this unsafe block! We'll have to wait for Rust 1.77 to release this though (and maybe a bit longer if we want to preserve MSRV).
1 parent 1ad5505 commit 9c753ea

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed
 

Diff for: ‎src/hazard.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,7 @@ impl<'domain, F, const N: usize> HazardPointerArray<'domain, F, N> {
294294
/// unusable. The borrow checker knows that individual elements in a `[_; N]` are distinct, and
295295
/// can be borrowed individually, but does not know that that is the case for `SomeType[i]`.
296296
pub fn as_refs<'array>(&'array mut self) -> [&'array mut HazardPointer<'domain, F>; N] {
297-
// TODO: replace with `self.haz_ptrs.each_mut().map(|v| &mut **v)` when each_mut stabilizes
298-
299-
let mut out: [MaybeUninit<&'array mut HazardPointer<'domain, F>>; N] =
300-
[(); N].map(|_| MaybeUninit::uninit());
301-
302-
for (i, hazptr) in self.haz_ptrs.iter_mut().enumerate() {
303-
out[i].write(hazptr);
304-
}
305-
306-
// Safety: we have initialized every element of the array with our for loop above
307-
out.map(|maybe_uninit| unsafe { maybe_uninit.assume_init() })
297+
self.haz_ptrs.each_mut().map(|v| &mut **v)
308298
}
309299

310300
/// Protect the value loaded from each [`AtomicPtr`], and dereference each one to `&T`.

0 commit comments

Comments
 (0)
Please sign in to comment.