@@ -4525,7 +4525,7 @@ impl<T> [T] {
45254525 /// to single elements, while if passed an array of ranges it gives back an array of
45264526 /// mutable references to slices.
45274527 ///
4528- /// For a safe alternative see [`get_many_mut `].
4528+ /// For a safe alternative see [`get_disjoint_mut `].
45294529 ///
45304530 /// # Safety
45314531 ///
@@ -4535,44 +4535,42 @@ impl<T> [T] {
45354535 /// # Examples
45364536 ///
45374537 /// ```
4538- /// #![feature(get_many_mut)]
4539- ///
45404538 /// let x = &mut [1, 2, 4];
45414539 ///
45424540 /// unsafe {
4543- /// let [a, b] = x.get_many_unchecked_mut ([0, 2]);
4541+ /// let [a, b] = x.get_disjoint_unchecked_mut ([0, 2]);
45444542 /// *a *= 10;
45454543 /// *b *= 100;
45464544 /// }
45474545 /// assert_eq!(x, &[10, 2, 400]);
45484546 ///
45494547 /// 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]);
45514549 /// a[0] = 8;
45524550 /// b[0] = 88;
45534551 /// b[1] = 888;
45544552 /// }
45554553 /// assert_eq!(x, &[8, 88, 888]);
45564554 ///
45574555 /// 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]);
45594557 /// a[0] = 11;
45604558 /// a[1] = 111;
45614559 /// b[0] = 1;
45624560 /// }
45634561 /// assert_eq!(x, &[1, 11, 111]);
45644562 /// ```
45654563 ///
4566- /// [`get_many_mut `]: slice::get_many_mut
4564+ /// [`get_disjoint_mut `]: slice::get_disjoint_mut
45674565 /// [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 " ) ]
45694567 #[ 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 > (
45714569 & mut self ,
45724570 indices : [ I ; N ] ,
45734571 ) -> [ & mut I :: Output ; N ]
45744572 where
4575- I : GetManyMutIndex + SliceIndex < Self > ,
4573+ I : GetDisjointMutIndex + SliceIndex < Self > ,
45764574 {
45774575 // NB: This implementation is written as it is because any variation of
45784576 // `indices.map(|i| self.get_unchecked_mut(i))` would make miri unhappy,
@@ -4611,42 +4609,40 @@ impl<T> [T] {
46114609 /// # Examples
46124610 ///
46134611 /// ```
4614- /// #![feature(get_many_mut)]
4615- ///
46164612 /// 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]) {
46184614 /// *a = 413;
46194615 /// *b = 612;
46204616 /// }
46214617 /// assert_eq!(v, &[413, 2, 612]);
46224618 ///
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]) {
46244620 /// a[0] = 8;
46254621 /// b[0] = 88;
46264622 /// b[1] = 888;
46274623 /// }
46284624 /// assert_eq!(v, &[8, 88, 888]);
46294625 ///
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]) {
46314627 /// a[0] = 11;
46324628 /// a[1] = 111;
46334629 /// b[0] = 1;
46344630 /// }
46354631 /// assert_eq!(v, &[1, 11, 111]);
46364632 /// ```
4637- #[ unstable ( feature = "get_many_mut" , issue = "104642 " ) ]
4633+ #[ stable ( feature = "get_many_mut" , since = "CURRENT_RUSTC_VERSION " ) ]
46384634 #[ inline]
4639- pub fn get_many_mut < I , const N : usize > (
4635+ pub fn get_disjoint_mut < I , const N : usize > (
46404636 & mut self ,
46414637 indices : [ I ; N ] ,
4642- ) -> Result < [ & mut I :: Output ; N ] , GetManyMutError >
4638+ ) -> Result < [ & mut I :: Output ; N ] , GetDisjointMutError >
46434639 where
4644- I : GetManyMutIndex + SliceIndex < Self > ,
4640+ I : GetDisjointMutIndex + SliceIndex < Self > ,
46454641 {
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
46484644 // are disjunct and in bounds.
4649- unsafe { Ok ( self . get_many_unchecked_mut ( indices) ) }
4645+ unsafe { Ok ( self . get_disjoint_unchecked_mut ( indices) ) }
46504646 }
46514647
46524648 /// Returns the index that an element reference points to.
@@ -4988,26 +4984,26 @@ impl<T, const N: usize> SlicePattern for [T; N] {
49884984/// This will do `binomial(N + 1, 2) = N * (N + 1) / 2 = 0, 1, 3, 6, 10, ..`
49894985/// comparison operations.
49904986#[ inline]
4991- fn get_many_check_valid < I : GetManyMutIndex , const N : usize > (
4987+ fn get_disjoint_check_valid < I : GetDisjointMutIndex , const N : usize > (
49924988 indices : & [ I ; N ] ,
49934989 len : usize ,
4994- ) -> Result < ( ) , GetManyMutError > {
4990+ ) -> Result < ( ) , GetDisjointMutError > {
49954991 // NB: The optimizer should inline the loops into a sequence
49964992 // of instructions without additional branching.
49974993 for ( i, idx) in indices. iter ( ) . enumerate ( ) {
49984994 if !idx. is_in_bounds ( len) {
4999- return Err ( GetManyMutError :: IndexOutOfBounds ) ;
4995+ return Err ( GetDisjointMutError :: IndexOutOfBounds ) ;
50004996 }
50014997 for idx2 in & indices[ ..i] {
50024998 if idx. is_overlapping ( idx2) {
5003- return Err ( GetManyMutError :: OverlappingIndices ) ;
4999+ return Err ( GetDisjointMutError :: OverlappingIndices ) ;
50045000 }
50055001 }
50065002 }
50075003 Ok ( ( ) )
50085004}
50095005
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 `].
50115007///
50125008/// It indicates one of two possible errors:
50135009/// - An index is out-of-bounds.
@@ -5017,74 +5013,75 @@ fn get_many_check_valid<I: GetManyMutIndex, const N: usize>(
50175013/// # Examples
50185014///
50195015/// ```
5020- /// #![feature(get_many_mut)]
5021- /// use std::slice::GetManyMutError;
5016+ /// use std::slice::GetDisjointMutError;
50225017///
50235018/// 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));
50265021/// ```
5027- #[ unstable ( feature = "get_many_mut" , issue = "104642 " ) ]
5022+ #[ stable ( feature = "get_many_mut" , since = "CURRENT_RUSTC_VERSION " ) ]
50285023#[ derive( Debug , Clone , PartialEq , Eq ) ]
5029- pub enum GetManyMutError {
5024+ pub enum GetDisjointMutError {
50305025 /// An index provided was out-of-bounds for the slice.
50315026 IndexOutOfBounds ,
50325027 /// Two indices provided were overlapping.
50335028 OverlappingIndices ,
50345029}
50355030
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 {
50385033 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
50395034 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" ,
50425037 } ;
50435038 fmt:: Display :: fmt ( msg, f)
50445039 }
50455040}
50465041
5047- mod private_get_many_mut_index {
5042+ mod private_get_disjoint_mut_index {
50485043 use super :: { Range , RangeInclusive , range} ;
50495044
5050- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5045+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50515046 pub trait Sealed { }
50525047
5053- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5048+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50545049 impl Sealed for usize { }
5055- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5050+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50565051 impl Sealed for Range < usize > { }
5057- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5052+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50585053 impl Sealed for RangeInclusive < usize > { }
5059- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5054+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50605055 impl Sealed for range:: Range < usize > { }
5061- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5056+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50625057 impl Sealed for range:: RangeInclusive < usize > { }
50635058}
50645059
5065- /// A helper trait for `<[T]>::get_many_mut ()`.
5060+ /// A helper trait for `<[T]>::get_disjoint_mut ()`.
50665061///
50675062/// # Safety
50685063///
50695064/// If `is_in_bounds()` returns `true` and `is_overlapping()` returns `false`,
50705065/// 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+ {
50735070 /// 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" ) ]
50755072 fn is_in_bounds ( & self , len : usize ) -> bool ;
50765073
50775074 /// Returns `true` if `self` overlaps with `other`.
50785075 ///
50795076 /// Note that we don't consider zero-length ranges to overlap at the beginning or the end,
50805077 /// 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" ) ]
50825079 fn is_overlapping ( & self , other : & Self ) -> bool ;
50835080}
50845081
5085- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5082+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50865083// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5087- unsafe impl GetManyMutIndex for usize {
5084+ unsafe impl GetDisjointMutIndex for usize {
50885085 #[ inline]
50895086 fn is_in_bounds ( & self , len : usize ) -> bool {
50905087 * self < len
@@ -5096,9 +5093,9 @@ unsafe impl GetManyMutIndex for usize {
50965093 }
50975094}
50985095
5099- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5096+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
51005097// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5101- unsafe impl GetManyMutIndex for Range < usize > {
5098+ unsafe impl GetDisjointMutIndex for Range < usize > {
51025099 #[ inline]
51035100 fn is_in_bounds ( & self , len : usize ) -> bool {
51045101 ( self . start <= self . end ) & ( self . end <= len)
@@ -5110,9 +5107,9 @@ unsafe impl GetManyMutIndex for Range<usize> {
51105107 }
51115108}
51125109
5113- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5110+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
51145111// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5115- unsafe impl GetManyMutIndex for RangeInclusive < usize > {
5112+ unsafe impl GetDisjointMutIndex for RangeInclusive < usize > {
51165113 #[ inline]
51175114 fn is_in_bounds ( & self , len : usize ) -> bool {
51185115 ( self . start <= self . end ) & ( self . end < len)
@@ -5124,9 +5121,9 @@ unsafe impl GetManyMutIndex for RangeInclusive<usize> {
51245121 }
51255122}
51265123
5127- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5124+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
51285125// 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 > {
51305127 #[ inline]
51315128 fn is_in_bounds ( & self , len : usize ) -> bool {
51325129 Range :: from ( * self ) . is_in_bounds ( len)
@@ -5138,9 +5135,9 @@ unsafe impl GetManyMutIndex for range::Range<usize> {
51385135 }
51395136}
51405137
5141- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5138+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
51425139// 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 > {
51445141 #[ inline]
51455142 fn is_in_bounds ( & self , len : usize ) -> bool {
51465143 RangeInclusive :: from ( * self ) . is_in_bounds ( len)
0 commit comments