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