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