@@ -4525,7 +4525,7 @@ impl<T> [T] {
4525
4525
/// to single elements, while if passed an array of ranges it gives back an array of
4526
4526
/// mutable references to slices.
4527
4527
///
4528
- /// For a safe alternative see [`get_many_mut `].
4528
+ /// For a safe alternative see [`get_disjoint_mut `].
4529
4529
///
4530
4530
/// # Safety
4531
4531
///
@@ -4535,44 +4535,42 @@ impl<T> [T] {
4535
4535
/// # Examples
4536
4536
///
4537
4537
/// ```
4538
- /// #![feature(get_many_mut)]
4539
- ///
4540
4538
/// let x = &mut [1, 2, 4];
4541
4539
///
4542
4540
/// unsafe {
4543
- /// let [a, b] = x.get_many_unchecked_mut ([0, 2]);
4541
+ /// let [a, b] = x.get_disjoint_unchecked_mut ([0, 2]);
4544
4542
/// *a *= 10;
4545
4543
/// *b *= 100;
4546
4544
/// }
4547
4545
/// assert_eq!(x, &[10, 2, 400]);
4548
4546
///
4549
4547
/// unsafe {
4550
- /// let [a, b] = x.get_many_unchecked_mut ([0..1, 1..3]);
4548
+ /// let [a, b] = x.get_disjoint_unchecked_mut ([0..1, 1..3]);
4551
4549
/// a[0] = 8;
4552
4550
/// b[0] = 88;
4553
4551
/// b[1] = 888;
4554
4552
/// }
4555
4553
/// assert_eq!(x, &[8, 88, 888]);
4556
4554
///
4557
4555
/// unsafe {
4558
- /// let [a, b] = x.get_many_unchecked_mut ([1..=2, 0..=0]);
4556
+ /// let [a, b] = x.get_disjoint_unchecked_mut ([1..=2, 0..=0]);
4559
4557
/// a[0] = 11;
4560
4558
/// a[1] = 111;
4561
4559
/// b[0] = 1;
4562
4560
/// }
4563
4561
/// assert_eq!(x, &[1, 11, 111]);
4564
4562
/// ```
4565
4563
///
4566
- /// [`get_many_mut `]: slice::get_many_mut
4564
+ /// [`get_disjoint_mut `]: slice::get_disjoint_mut
4567
4565
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
4568
- #[ unstable ( feature = "get_many_mut" , issue = "104642 " ) ]
4566
+ #[ stable ( feature = "get_many_mut" , since = "CURRENT_RUSTC_VERSION " ) ]
4569
4567
#[ inline]
4570
- pub unsafe fn get_many_unchecked_mut < I , const N : usize > (
4568
+ pub unsafe fn get_disjoint_unchecked_mut < I , const N : usize > (
4571
4569
& mut self ,
4572
4570
indices : [ I ; N ] ,
4573
4571
) -> [ & mut I :: Output ; N ]
4574
4572
where
4575
- I : GetManyMutIndex + SliceIndex < Self > ,
4573
+ I : GetDisjointMutIndex + SliceIndex < Self > ,
4576
4574
{
4577
4575
// NB: This implementation is written as it is because any variation of
4578
4576
// `indices.map(|i| self.get_unchecked_mut(i))` would make miri unhappy,
@@ -4611,42 +4609,40 @@ impl<T> [T] {
4611
4609
/// # Examples
4612
4610
///
4613
4611
/// ```
4614
- /// #![feature(get_many_mut)]
4615
- ///
4616
4612
/// let v = &mut [1, 2, 3];
4617
- /// if let Ok([a, b]) = v.get_many_mut ([0, 2]) {
4613
+ /// if let Ok([a, b]) = v.get_disjoint_mut ([0, 2]) {
4618
4614
/// *a = 413;
4619
4615
/// *b = 612;
4620
4616
/// }
4621
4617
/// assert_eq!(v, &[413, 2, 612]);
4622
4618
///
4623
- /// if let Ok([a, b]) = v.get_many_mut ([0..1, 1..3]) {
4619
+ /// if let Ok([a, b]) = v.get_disjoint_mut ([0..1, 1..3]) {
4624
4620
/// a[0] = 8;
4625
4621
/// b[0] = 88;
4626
4622
/// b[1] = 888;
4627
4623
/// }
4628
4624
/// assert_eq!(v, &[8, 88, 888]);
4629
4625
///
4630
- /// if let Ok([a, b]) = v.get_many_mut ([1..=2, 0..=0]) {
4626
+ /// if let Ok([a, b]) = v.get_disjoint_mut ([1..=2, 0..=0]) {
4631
4627
/// a[0] = 11;
4632
4628
/// a[1] = 111;
4633
4629
/// b[0] = 1;
4634
4630
/// }
4635
4631
/// assert_eq!(v, &[1, 11, 111]);
4636
4632
/// ```
4637
- #[ unstable ( feature = "get_many_mut" , issue = "104642 " ) ]
4633
+ #[ stable ( feature = "get_many_mut" , since = "CURRENT_RUSTC_VERSION " ) ]
4638
4634
#[ inline]
4639
- pub fn get_many_mut < I , const N : usize > (
4635
+ pub fn get_disjoint_mut < I , const N : usize > (
4640
4636
& mut self ,
4641
4637
indices : [ I ; N ] ,
4642
- ) -> Result < [ & mut I :: Output ; N ] , GetManyMutError >
4638
+ ) -> Result < [ & mut I :: Output ; N ] , GetDisjointMutError >
4643
4639
where
4644
- I : GetManyMutIndex + SliceIndex < Self > ,
4640
+ I : GetDisjointMutIndex + SliceIndex < Self > ,
4645
4641
{
4646
- get_many_check_valid ( & indices, self . len ( ) ) ?;
4647
- // SAFETY: The `get_many_check_valid ()` call checked that all indices
4642
+ get_disjoint_check_valid ( & indices, self . len ( ) ) ?;
4643
+ // SAFETY: The `get_disjoint_check_valid ()` call checked that all indices
4648
4644
// are disjunct and in bounds.
4649
- unsafe { Ok ( self . get_many_unchecked_mut ( indices) ) }
4645
+ unsafe { Ok ( self . get_disjoint_unchecked_mut ( indices) ) }
4650
4646
}
4651
4647
4652
4648
/// Returns the index that an element reference points to.
@@ -4988,26 +4984,26 @@ impl<T, const N: usize> SlicePattern for [T; N] {
4988
4984
/// This will do `binomial(N + 1, 2) = N * (N + 1) / 2 = 0, 1, 3, 6, 10, ..`
4989
4985
/// comparison operations.
4990
4986
#[ inline]
4991
- fn get_many_check_valid < I : GetManyMutIndex , const N : usize > (
4987
+ fn get_disjoint_check_valid < I : GetDisjointMutIndex , const N : usize > (
4992
4988
indices : & [ I ; N ] ,
4993
4989
len : usize ,
4994
- ) -> Result < ( ) , GetManyMutError > {
4990
+ ) -> Result < ( ) , GetDisjointMutError > {
4995
4991
// NB: The optimizer should inline the loops into a sequence
4996
4992
// of instructions without additional branching.
4997
4993
for ( i, idx) in indices. iter ( ) . enumerate ( ) {
4998
4994
if !idx. is_in_bounds ( len) {
4999
- return Err ( GetManyMutError :: IndexOutOfBounds ) ;
4995
+ return Err ( GetDisjointMutError :: IndexOutOfBounds ) ;
5000
4996
}
5001
4997
for idx2 in & indices[ ..i] {
5002
4998
if idx. is_overlapping ( idx2) {
5003
- return Err ( GetManyMutError :: OverlappingIndices ) ;
4999
+ return Err ( GetDisjointMutError :: OverlappingIndices ) ;
5004
5000
}
5005
5001
}
5006
5002
}
5007
5003
Ok ( ( ) )
5008
5004
}
5009
5005
5010
- /// The error type returned by [`get_many_mut `][`slice::get_many_mut `].
5006
+ /// The error type returned by [`get_disjoint_mut `][`slice::get_disjoint_mut `].
5011
5007
///
5012
5008
/// It indicates one of two possible errors:
5013
5009
/// - An index is out-of-bounds.
@@ -5017,74 +5013,75 @@ fn get_many_check_valid<I: GetManyMutIndex, const N: usize>(
5017
5013
/// # Examples
5018
5014
///
5019
5015
/// ```
5020
- /// #![feature(get_many_mut)]
5021
- /// use std::slice::GetManyMutError;
5016
+ /// use std::slice::GetDisjointMutError;
5022
5017
///
5023
5018
/// let v = &mut [1, 2, 3];
5024
- /// assert_eq!(v.get_many_mut ([0, 999]), Err(GetManyMutError ::IndexOutOfBounds));
5025
- /// assert_eq!(v.get_many_mut ([1, 1]), Err(GetManyMutError ::OverlappingIndices));
5019
+ /// assert_eq!(v.get_disjoint_mut ([0, 999]), Err(GetDisjointMutError ::IndexOutOfBounds));
5020
+ /// assert_eq!(v.get_disjoint_mut ([1, 1]), Err(GetDisjointMutError ::OverlappingIndices));
5026
5021
/// ```
5027
- #[ unstable ( feature = "get_many_mut" , issue = "104642 " ) ]
5022
+ #[ stable ( feature = "get_many_mut" , since = "CURRENT_RUSTC_VERSION " ) ]
5028
5023
#[ derive( Debug , Clone , PartialEq , Eq ) ]
5029
- pub enum GetManyMutError {
5024
+ pub enum GetDisjointMutError {
5030
5025
/// An index provided was out-of-bounds for the slice.
5031
5026
IndexOutOfBounds ,
5032
5027
/// Two indices provided were overlapping.
5033
5028
OverlappingIndices ,
5034
5029
}
5035
5030
5036
- #[ unstable ( feature = "get_many_mut" , issue = "104642 " ) ]
5037
- impl fmt:: Display for GetManyMutError {
5031
+ #[ stable ( feature = "get_many_mut" , since = "CURRENT_RUSTC_VERSION " ) ]
5032
+ impl fmt:: Display for GetDisjointMutError {
5038
5033
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
5039
5034
let msg = match self {
5040
- GetManyMutError :: IndexOutOfBounds => "an index is out of bounds" ,
5041
- GetManyMutError :: OverlappingIndices => "there were overlapping indices" ,
5035
+ GetDisjointMutError :: IndexOutOfBounds => "an index is out of bounds" ,
5036
+ GetDisjointMutError :: OverlappingIndices => "there were overlapping indices" ,
5042
5037
} ;
5043
5038
fmt:: Display :: fmt ( msg, f)
5044
5039
}
5045
5040
}
5046
5041
5047
- mod private_get_many_mut_index {
5042
+ mod private_get_disjoint_mut_index {
5048
5043
use super :: { Range , RangeInclusive , range} ;
5049
5044
5050
- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5045
+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
5051
5046
pub trait Sealed { }
5052
5047
5053
- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5048
+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
5054
5049
impl Sealed for usize { }
5055
- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5050
+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
5056
5051
impl Sealed for Range < usize > { }
5057
- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5052
+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
5058
5053
impl Sealed for RangeInclusive < usize > { }
5059
- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5054
+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
5060
5055
impl Sealed for range:: Range < usize > { }
5061
- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5056
+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
5062
5057
impl Sealed for range:: RangeInclusive < usize > { }
5063
5058
}
5064
5059
5065
- /// A helper trait for `<[T]>::get_many_mut ()`.
5060
+ /// A helper trait for `<[T]>::get_disjoint_mut ()`.
5066
5061
///
5067
5062
/// # Safety
5068
5063
///
5069
5064
/// If `is_in_bounds()` returns `true` and `is_overlapping()` returns `false`,
5070
5065
/// it must be safe to index the slice with the indices.
5071
- #[ unstable( feature = "get_many_mut_helpers" , issue = "none" ) ]
5072
- pub unsafe trait GetManyMutIndex : Clone + private_get_many_mut_index:: Sealed {
5066
+ #[ unstable( feature = "get_disjoint_mut_helpers" , issue = "none" ) ]
5067
+ pub unsafe trait GetDisjointMutIndex :
5068
+ Clone + private_get_disjoint_mut_index:: Sealed
5069
+ {
5073
5070
/// Returns `true` if `self` is in bounds for `len` slice elements.
5074
- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5071
+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
5075
5072
fn is_in_bounds ( & self , len : usize ) -> bool ;
5076
5073
5077
5074
/// Returns `true` if `self` overlaps with `other`.
5078
5075
///
5079
5076
/// Note that we don't consider zero-length ranges to overlap at the beginning or the end,
5080
5077
/// but do consider them to overlap in the middle.
5081
- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5078
+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
5082
5079
fn is_overlapping ( & self , other : & Self ) -> bool ;
5083
5080
}
5084
5081
5085
- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5082
+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
5086
5083
// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5087
- unsafe impl GetManyMutIndex for usize {
5084
+ unsafe impl GetDisjointMutIndex for usize {
5088
5085
#[ inline]
5089
5086
fn is_in_bounds ( & self , len : usize ) -> bool {
5090
5087
* self < len
@@ -5096,9 +5093,9 @@ unsafe impl GetManyMutIndex for usize {
5096
5093
}
5097
5094
}
5098
5095
5099
- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5096
+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
5100
5097
// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5101
- unsafe impl GetManyMutIndex for Range < usize > {
5098
+ unsafe impl GetDisjointMutIndex for Range < usize > {
5102
5099
#[ inline]
5103
5100
fn is_in_bounds ( & self , len : usize ) -> bool {
5104
5101
( self . start <= self . end ) & ( self . end <= len)
@@ -5110,9 +5107,9 @@ unsafe impl GetManyMutIndex for Range<usize> {
5110
5107
}
5111
5108
}
5112
5109
5113
- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5110
+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
5114
5111
// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5115
- unsafe impl GetManyMutIndex for RangeInclusive < usize > {
5112
+ unsafe impl GetDisjointMutIndex for RangeInclusive < usize > {
5116
5113
#[ inline]
5117
5114
fn is_in_bounds ( & self , len : usize ) -> bool {
5118
5115
( self . start <= self . end ) & ( self . end < len)
@@ -5124,9 +5121,9 @@ unsafe impl GetManyMutIndex for RangeInclusive<usize> {
5124
5121
}
5125
5122
}
5126
5123
5127
- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5124
+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
5128
5125
// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5129
- unsafe impl GetManyMutIndex for range:: Range < usize > {
5126
+ unsafe impl GetDisjointMutIndex for range:: Range < usize > {
5130
5127
#[ inline]
5131
5128
fn is_in_bounds ( & self , len : usize ) -> bool {
5132
5129
Range :: from ( * self ) . is_in_bounds ( len)
@@ -5138,9 +5135,9 @@ unsafe impl GetManyMutIndex for range::Range<usize> {
5138
5135
}
5139
5136
}
5140
5137
5141
- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5138
+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
5142
5139
// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5143
- unsafe impl GetManyMutIndex for range:: RangeInclusive < usize > {
5140
+ unsafe impl GetDisjointMutIndex for range:: RangeInclusive < usize > {
5144
5141
#[ inline]
5145
5142
fn is_in_bounds ( & self , len : usize ) -> bool {
5146
5143
RangeInclusive :: from ( * self ) . is_in_bounds ( len)
0 commit comments