Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less unsafe with array_methods #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/hazard.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::sync::atomic::AtomicPtr;
use crate::{record::HazPtrRecord, Domain};
use core::marker::PhantomData;
use core::mem::{ManuallyDrop, MaybeUninit};

Check warning on line 4 in src/hazard.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `MaybeUninit`

warning: unused import: `MaybeUninit` --> src/hazard.rs:4:31 | 4 | use core::mem::{ManuallyDrop, MaybeUninit}; | ^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
use core::ptr::NonNull;
use core::sync::atomic::Ordering;

Expand Down Expand Up @@ -294,17 +294,7 @@
/// 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:/rust-lang/rust/issues/76118> for more information
}

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