Skip to content

Commit

Permalink
Less unsafe with array_methods
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
jonhoo committed Jan 28, 2024
1 parent 1ad5505 commit 9c753ea
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions src/hazard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,7 @@ impl<'domain, F, const N: usize> HazardPointerArray<'domain, F, N> {
/// unusable. The borrow checker knows that individual elements in a `[_; N]` are distinct, and
/// can be borrowed individually, but does not know that that is the case for `SomeType[i]`.
pub fn as_refs<'array>(&'array mut self) -> [&'array mut HazardPointer<'domain, F>; N] {
// TODO: replace with `self.haz_ptrs.each_mut().map(|v| &mut **v)` when each_mut stabilizes

let mut out: [MaybeUninit<&'array mut HazardPointer<'domain, F>>; N] =
[(); N].map(|_| MaybeUninit::uninit());

for (i, hazptr) in self.haz_ptrs.iter_mut().enumerate() {
out[i].write(hazptr);
}

// Safety: we have initialized every element of the array with our for loop above
out.map(|maybe_uninit| unsafe { maybe_uninit.assume_init() })
self.haz_ptrs.each_mut().map(|v| &mut **v)

Check failure on line 297 in src/hazard.rs

View workflow job for this annotation

GitHub Actions / clippy

use of unstable library feature 'array_methods'

error[E0658]: use of unstable library feature 'array_methods' --> src/hazard.rs:297:23 | 297 | self.haz_ptrs.each_mut().map(|v| &mut **v) | ^^^^^^^^ | = note: see issue #76118 <https://github.com/rust-lang/rust/issues/76118> for more information
}

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

0 comments on commit 9c753ea

Please sign in to comment.