@@ -342,12 +342,10 @@ where
342
342
}
343
343
344
344
#[ 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 >
349
346
where
350
- F : FnOnce ( NonNull < T > ) -> NonNull < U > ,
347
+ F : ~const FnOnce ( NonNull < T > ) -> NonNull < U > ,
348
+ A : Access ,
351
349
U : ?Sized ,
352
350
{
353
351
unsafe { VolatilePtr :: new_generic ( f ( self . pointer ) ) }
@@ -363,9 +361,9 @@ where
363
361
}
364
362
365
363
#[ 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 >
367
365
where
368
- F : FnOnce ( NonNull < T > ) -> NonNull < U > ,
366
+ F : ~ const FnOnce ( NonNull < T > ) -> NonNull < U > ,
369
367
U : ?Sized ,
370
368
{
371
369
unsafe { VolatilePtr :: new_generic ( f ( self . pointer ) ) }
@@ -479,16 +477,24 @@ impl<'a, T, A> VolatilePtr<'a, [T], A> {
479
477
}
480
478
481
479
#[ 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
+ {
486
484
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
+ }
491
495
}
496
+
497
+ unsafe { self . map_const ( Mapper { index } ) }
492
498
}
493
499
494
500
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> {
502
508
}
503
509
504
510
#[ 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 > {
506
512
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 ,
511
516
}
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 } ) }
512
526
}
513
527
514
528
/// Returns an iterator over the slice.
0 commit comments