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