@@ -6,9 +6,10 @@ use crate::ub_checks::assert_unsafe_precondition;
6
6
use crate :: { ops, range} ;
7
7
8
8
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
9
- impl < T , I > ops:: Index < I > for [ T ]
9
+ #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
10
+ impl < T , I > const ops:: Index < I > for [ T ]
10
11
where
11
- I : SliceIndex < [ T ] > ,
12
+ I : ~ const SliceIndex < [ T ] > ,
12
13
{
13
14
type Output = I :: Output ;
14
15
19
20
}
20
21
21
22
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
22
- impl < T , I > ops:: IndexMut < I > for [ T ]
23
+ #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
24
+ impl < T , I > const ops:: IndexMut < I > for [ T ]
23
25
where
24
- I : SliceIndex < [ T ] > ,
26
+ I : ~ const SliceIndex < [ T ] > ,
25
27
{
26
28
#[ inline( always) ]
27
29
fn index_mut ( & mut self , index : I ) -> & mut I :: Output {
@@ -158,6 +160,8 @@ mod private_slice_index {
158
160
message = "the type `{T}` cannot be indexed by `{Self}`" ,
159
161
label = "slice indices are of type `usize` or ranges of `usize`"
160
162
) ]
163
+ #[ const_trait]
164
+ #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
161
165
pub unsafe trait SliceIndex < T : ?Sized > : private_slice_index:: Sealed {
162
166
/// The output type returned by methods.
163
167
#[ stable( feature = "slice_get_slice" , since = "1.28.0" ) ]
@@ -208,7 +212,8 @@ pub unsafe trait SliceIndex<T: ?Sized>: private_slice_index::Sealed {
208
212
209
213
/// The methods `index` and `index_mut` panic if the index is out of bounds.
210
214
#[ stable( feature = "slice_get_slice_impls" , since = "1.15.0" ) ]
211
- unsafe impl < T > SliceIndex < [ T ] > for usize {
215
+ #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
216
+ unsafe impl < T > const SliceIndex < [ T ] > for usize {
212
217
type Output = T ;
213
218
214
219
#[ inline]
@@ -278,7 +283,8 @@ unsafe impl<T> SliceIndex<[T]> for usize {
278
283
279
284
/// Because `IndexRange` guarantees `start <= end`, fewer checks are needed here
280
285
/// than there are for a general `Range<usize>` (which might be `100..3`).
281
- unsafe impl < T > SliceIndex < [ T ] > for ops:: IndexRange {
286
+ #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
287
+ unsafe impl < T > const SliceIndex < [ T ] > for ops:: IndexRange {
282
288
type Output = [ T ] ;
283
289
284
290
#[ inline]
@@ -354,7 +360,8 @@ unsafe impl<T> SliceIndex<[T]> for ops::IndexRange {
354
360
/// - the start of the range is greater than the end of the range or
355
361
/// - the end of the range is out of bounds.
356
362
#[ stable( feature = "slice_get_slice_impls" , since = "1.15.0" ) ]
357
- unsafe impl < T > SliceIndex < [ T ] > for ops:: Range < usize > {
363
+ #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
364
+ unsafe impl < T > const SliceIndex < [ T ] > for ops:: Range < usize > {
358
365
type Output = [ T ] ;
359
366
360
367
#[ inline]
@@ -453,7 +460,8 @@ unsafe impl<T> SliceIndex<[T]> for ops::Range<usize> {
453
460
}
454
461
455
462
#[ unstable( feature = "new_range_api" , issue = "125687" ) ]
456
- unsafe impl < T > SliceIndex < [ T ] > for range:: Range < usize > {
463
+ #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
464
+ unsafe impl < T > const SliceIndex < [ T ] > for range:: Range < usize > {
457
465
type Output = [ T ] ;
458
466
459
467
#[ inline]
@@ -491,7 +499,8 @@ unsafe impl<T> SliceIndex<[T]> for range::Range<usize> {
491
499
492
500
/// The methods `index` and `index_mut` panic if the end of the range is out of bounds.
493
501
#[ stable( feature = "slice_get_slice_impls" , since = "1.15.0" ) ]
494
- unsafe impl < T > SliceIndex < [ T ] > for ops:: RangeTo < usize > {
502
+ #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
503
+ unsafe impl < T > const SliceIndex < [ T ] > for ops:: RangeTo < usize > {
495
504
type Output = [ T ] ;
496
505
497
506
#[ inline]
@@ -529,7 +538,8 @@ unsafe impl<T> SliceIndex<[T]> for ops::RangeTo<usize> {
529
538
530
539
/// The methods `index` and `index_mut` panic if the start of the range is out of bounds.
531
540
#[ stable( feature = "slice_get_slice_impls" , since = "1.15.0" ) ]
532
- unsafe impl < T > SliceIndex < [ T ] > for ops:: RangeFrom < usize > {
541
+ #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
542
+ unsafe impl < T > const SliceIndex < [ T ] > for ops:: RangeFrom < usize > {
533
543
type Output = [ T ] ;
534
544
535
545
#[ inline]
@@ -574,7 +584,8 @@ unsafe impl<T> SliceIndex<[T]> for ops::RangeFrom<usize> {
574
584
}
575
585
576
586
#[ unstable( feature = "new_range_api" , issue = "125687" ) ]
577
- unsafe impl < T > SliceIndex < [ T ] > for range:: RangeFrom < usize > {
587
+ #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
588
+ unsafe impl < T > const SliceIndex < [ T ] > for range:: RangeFrom < usize > {
578
589
type Output = [ T ] ;
579
590
580
591
#[ inline]
@@ -611,7 +622,8 @@ unsafe impl<T> SliceIndex<[T]> for range::RangeFrom<usize> {
611
622
}
612
623
613
624
#[ stable( feature = "slice_get_slice_impls" , since = "1.15.0" ) ]
614
- unsafe impl < T > SliceIndex < [ T ] > for ops:: RangeFull {
625
+ #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
626
+ unsafe impl < T > const SliceIndex < [ T ] > for ops:: RangeFull {
615
627
type Output = [ T ] ;
616
628
617
629
#[ inline]
@@ -650,7 +662,8 @@ unsafe impl<T> SliceIndex<[T]> for ops::RangeFull {
650
662
/// - the start of the range is greater than the end of the range or
651
663
/// - the end of the range is out of bounds.
652
664
#[ stable( feature = "inclusive_range" , since = "1.26.0" ) ]
653
- unsafe impl < T > SliceIndex < [ T ] > for ops:: RangeInclusive < usize > {
665
+ #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
666
+ unsafe impl < T > const SliceIndex < [ T ] > for ops:: RangeInclusive < usize > {
654
667
type Output = [ T ] ;
655
668
656
669
#[ inline]
@@ -693,7 +706,8 @@ unsafe impl<T> SliceIndex<[T]> for ops::RangeInclusive<usize> {
693
706
}
694
707
695
708
#[ unstable( feature = "new_range_api" , issue = "125687" ) ]
696
- unsafe impl < T > SliceIndex < [ T ] > for range:: RangeInclusive < usize > {
709
+ #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
710
+ unsafe impl < T > const SliceIndex < [ T ] > for range:: RangeInclusive < usize > {
697
711
type Output = [ T ] ;
698
712
699
713
#[ inline]
@@ -731,7 +745,8 @@ unsafe impl<T> SliceIndex<[T]> for range::RangeInclusive<usize> {
731
745
732
746
/// The methods `index` and `index_mut` panic if the end of the range is out of bounds.
733
747
#[ stable( feature = "inclusive_range" , since = "1.26.0" ) ]
734
- unsafe impl < T > SliceIndex < [ T ] > for ops:: RangeToInclusive < usize > {
748
+ #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
749
+ unsafe impl < T > const SliceIndex < [ T ] > for ops:: RangeToInclusive < usize > {
735
750
type Output = [ T ] ;
736
751
737
752
#[ inline]
0 commit comments