@@ -12,7 +12,7 @@ use crate::cmp::Ordering::{self, Equal, Greater, Less};
12
12
use crate :: intrinsics:: assume;
13
13
use crate :: marker:: { self , Copy } ;
14
14
use crate :: mem;
15
- use crate :: ops:: { Bound , FnMut , Range , RangeBounds } ;
15
+ use crate :: ops:: { FnMut , Range , RangeBounds } ;
16
16
use crate :: option:: Option ;
17
17
use crate :: option:: Option :: { None , Some } ;
18
18
use crate :: ptr:: { self , NonNull } ;
@@ -72,8 +72,8 @@ pub use sort::heapsort;
72
72
#[ stable( feature = "slice_get_slice" , since = "1.28.0" ) ]
73
73
pub use index:: SliceIndex ;
74
74
75
- use index :: { slice_end_index_len_fail , slice_index_order_fail } ;
76
- use index:: { slice_end_index_overflow_fail , slice_start_index_overflow_fail } ;
75
+ # [ unstable ( feature = "slice_check_range" , issue = "76393" ) ]
76
+ pub use index:: check_range ;
77
77
78
78
#[ lang = "slice" ]
79
79
#[ cfg( not( test) ) ]
@@ -378,79 +378,6 @@ impl<T> [T] {
378
378
unsafe { & mut * index. get_unchecked_mut ( self ) }
379
379
}
380
380
381
- /// Converts a range over this slice to [`Range`].
382
- ///
383
- /// The returned range is safe to pass to [`get_unchecked`] and [`get_unchecked_mut`].
384
- ///
385
- /// [`get_unchecked`]: #method.get_unchecked
386
- /// [`get_unchecked_mut`]: #method.get_unchecked_mut
387
- ///
388
- /// # Panics
389
- ///
390
- /// Panics if the range is out of bounds.
391
- ///
392
- /// # Examples
393
- ///
394
- /// ```
395
- /// #![feature(slice_check_range)]
396
- ///
397
- /// let v = [10, 40, 30];
398
- /// assert_eq!(1..2, v.check_range(1..2));
399
- /// assert_eq!(0..2, v.check_range(..2));
400
- /// assert_eq!(1..3, v.check_range(1..));
401
- /// ```
402
- ///
403
- /// Panics when [`Index::index`] would panic:
404
- ///
405
- /// ```should_panic
406
- /// #![feature(slice_check_range)]
407
- ///
408
- /// [10, 40, 30].check_range(2..1);
409
- /// ```
410
- ///
411
- /// ```should_panic
412
- /// #![feature(slice_check_range)]
413
- ///
414
- /// [10, 40, 30].check_range(1..4);
415
- /// ```
416
- ///
417
- /// ```should_panic
418
- /// #![feature(slice_check_range)]
419
- ///
420
- /// [10, 40, 30].check_range(1..=usize::MAX);
421
- /// ```
422
- ///
423
- /// [`Index::index`]: crate::ops::Index::index
424
- #[ track_caller]
425
- #[ unstable( feature = "slice_check_range" , issue = "76393" ) ]
426
- pub fn check_range < R : RangeBounds < usize > > ( & self , range : R ) -> Range < usize > {
427
- let start = match range. start_bound ( ) {
428
- Bound :: Included ( & start) => start,
429
- Bound :: Excluded ( start) => {
430
- start. checked_add ( 1 ) . unwrap_or_else ( || slice_start_index_overflow_fail ( ) )
431
- }
432
- Bound :: Unbounded => 0 ,
433
- } ;
434
-
435
- let len = self . len ( ) ;
436
- let end = match range. end_bound ( ) {
437
- Bound :: Included ( end) => {
438
- end. checked_add ( 1 ) . unwrap_or_else ( || slice_end_index_overflow_fail ( ) )
439
- }
440
- Bound :: Excluded ( & end) => end,
441
- Bound :: Unbounded => len,
442
- } ;
443
-
444
- if start > end {
445
- slice_index_order_fail ( start, end) ;
446
- }
447
- if end > len {
448
- slice_end_index_len_fail ( end, len) ;
449
- }
450
-
451
- Range { start, end }
452
- }
453
-
454
381
/// Returns a raw pointer to the slice's buffer.
455
382
///
456
383
/// The caller must ensure that the slice outlives the pointer this
@@ -2794,7 +2721,7 @@ impl<T> [T] {
2794
2721
where
2795
2722
T : Copy ,
2796
2723
{
2797
- let Range { start : src_start, end : src_end } = self . check_range ( src) ;
2724
+ let Range { start : src_start, end : src_end } = check_range ( self . len ( ) , src) ;
2798
2725
let count = src_end - src_start;
2799
2726
assert ! ( dest <= self . len( ) - count, "dest is out of bounds" ) ;
2800
2727
// SAFETY: the conditions for `ptr::copy` have all been checked above,
0 commit comments