Skip to content

Commit a143e0b

Browse files
committed
Update very_unstable to work with new access types and latest nightly
1 parent bbb23f4 commit a143e0b

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#![cfg_attr(feature = "very_unstable", feature(const_slice_ptr_len))]
77
#![cfg_attr(feature = "very_unstable", feature(const_trait_impl))]
88
#![cfg_attr(feature = "very_unstable", feature(const_mut_refs))]
9-
#![cfg_attr(feature = "very_unstable", allow(incomplete_features))]
9+
#![cfg_attr(feature = "very_unstable", feature(inline_const))]
10+
#![cfg_attr(feature = "very_unstable", feature(unboxed_closures))]
11+
#![cfg_attr(feature = "very_unstable", feature(fn_traits))]
1012
#![cfg_attr(all(feature = "unstable", test), feature(slice_as_chunks))]
1113
#![warn(missing_docs)]
1214
#![deny(unsafe_op_in_unsafe_fn)]

src/ptr.rs

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,10 @@ where
342342
}
343343

344344
#[cfg(feature = "very_unstable")]
345-
pub const unsafe fn map_const<F, U>(
346-
self,
347-
f: F,
348-
) -> VolatilePtr<'a, U, Access<R, access_ptr::NoAccess>>
345+
pub const unsafe fn map_const<F, U>(self, f: F) -> VolatilePtr<'a, U, A::RestrictShared>
349346
where
350-
F: FnOnce(NonNull<T>) -> NonNull<U>,
347+
F: ~const FnOnce(NonNull<T>) -> NonNull<U>,
348+
A: Access,
351349
U: ?Sized,
352350
{
353351
unsafe { VolatilePtr::new_generic(f(self.pointer)) }
@@ -363,9 +361,9 @@ where
363361
}
364362

365363
#[cfg(feature = "very_unstable")]
366-
pub const unsafe fn map_mut_const<F, U>(self, f: F) -> VolatilePtr<'a, U, Access<R, W>>
364+
pub const unsafe fn map_mut_const<F, U>(self, f: F) -> VolatilePtr<'a, U, A>
367365
where
368-
F: FnOnce(NonNull<T>) -> NonNull<U>,
366+
F: ~const FnOnce(NonNull<T>) -> NonNull<U>,
369367
U: ?Sized,
370368
{
371369
unsafe { VolatilePtr::new_generic(f(self.pointer)) }
@@ -479,16 +477,24 @@ impl<'a, T, A> VolatilePtr<'a, [T], A> {
479477
}
480478

481479
#[cfg(feature = "very_unstable")]
482-
pub const fn index_const(
483-
self,
484-
index: usize,
485-
) -> VolatilePtr<'a, T, Access<R, access_ptr::NoAccess>> {
480+
pub const fn index_const(self, index: usize) -> VolatilePtr<'a, T, A::RestrictShared>
481+
where
482+
A: Access,
483+
{
486484
assert!(index < self.pointer.len(), "index out of bounds");
487-
unsafe {
488-
self.map_const(|slice| {
489-
NonNull::new_unchecked(slice.as_non_null_ptr().as_ptr().add(index))
490-
})
485+
486+
struct Mapper {
487+
index: usize,
488+
}
489+
impl<T> const FnOnce<(NonNull<[T]>,)> for Mapper {
490+
type Output = NonNull<T>;
491+
492+
extern "rust-call" fn call_once(self, (slice,): (NonNull<[T]>,)) -> Self::Output {
493+
unsafe { NonNull::new_unchecked(slice.as_non_null_ptr().as_ptr().add(self.index)) }
494+
}
491495
}
496+
497+
unsafe { self.map_const(Mapper { index }) }
492498
}
493499

494500
pub fn index_mut<I>(self, index: I) -> VolatilePtr<'a, <I as SliceIndex<[T]>>::Output, A>
@@ -502,13 +508,21 @@ impl<'a, T, A> VolatilePtr<'a, [T], A> {
502508
}
503509

504510
#[cfg(feature = "very_unstable")]
505-
pub const fn index_mut_const(self, index: usize) -> VolatilePtr<'a, T, Access<R, W>> {
511+
pub const fn index_mut_const(self, index: usize) -> VolatilePtr<'a, T, A> {
506512
assert!(index < self.pointer.len(), "index out of bounds");
507-
unsafe {
508-
self.map_mut_const(|slice| {
509-
NonNull::new_unchecked(slice.as_non_null_ptr().as_ptr().add(index))
510-
})
513+
514+
struct Mapper {
515+
index: usize,
511516
}
517+
impl<T> const FnOnce<(NonNull<[T]>,)> for Mapper {
518+
type Output = NonNull<T>;
519+
520+
extern "rust-call" fn call_once(self, (slice,): (NonNull<[T]>,)) -> Self::Output {
521+
unsafe { NonNull::new_unchecked(slice.as_non_null_ptr().as_ptr().add(self.index)) }
522+
}
523+
}
524+
525+
unsafe { self.map_mut_const(Mapper { index }) }
512526
}
513527

514528
/// Returns an iterator over the slice.

0 commit comments

Comments
 (0)