@@ -4531,7 +4531,7 @@ impl<T> [T] {
45314531 /// to single elements, while if passed an array of ranges it gives back an array of
45324532 /// mutable references to slices.
45334533 ///
4534- /// For a safe alternative see [`get_many_mut `].
4534+ /// For a safe alternative see [`get_disjoint_mut `].
45354535 ///
45364536 /// # Safety
45374537 ///
@@ -4541,44 +4541,42 @@ impl<T> [T] {
45414541 /// # Examples
45424542 ///
45434543 /// ```
4544- /// #![feature(get_many_mut)]
4545- ///
45464544 /// let x = &mut [1, 2, 4];
45474545 ///
45484546 /// unsafe {
4549- /// let [a, b] = x.get_many_unchecked_mut ([0, 2]);
4547+ /// let [a, b] = x.get_disjoint_unchecked_mut ([0, 2]);
45504548 /// *a *= 10;
45514549 /// *b *= 100;
45524550 /// }
45534551 /// assert_eq!(x, &[10, 2, 400]);
45544552 ///
45554553 /// 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]);
45574555 /// a[0] = 8;
45584556 /// b[0] = 88;
45594557 /// b[1] = 888;
45604558 /// }
45614559 /// assert_eq!(x, &[8, 88, 888]);
45624560 ///
45634561 /// 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]);
45654563 /// a[0] = 11;
45664564 /// a[1] = 111;
45674565 /// b[0] = 1;
45684566 /// }
45694567 /// assert_eq!(x, &[1, 11, 111]);
45704568 /// ```
45714569 ///
4572- /// [`get_many_mut `]: slice::get_many_mut
4570+ /// [`get_disjoint_mut `]: slice::get_disjoint_mut
45734571 /// [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 " ) ]
45754573 #[ 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 > (
45774575 & mut self ,
45784576 indices : [ I ; N ] ,
45794577 ) -> [ & mut I :: Output ; N ]
45804578 where
4581- I : GetManyMutIndex + SliceIndex < Self > ,
4579+ I : GetDisjointMutIndex + SliceIndex < Self > ,
45824580 {
45834581 // NB: This implementation is written as it is because any variation of
45844582 // `indices.map(|i| self.get_unchecked_mut(i))` would make miri unhappy,
@@ -4617,42 +4615,40 @@ impl<T> [T] {
46174615 /// # Examples
46184616 ///
46194617 /// ```
4620- /// #![feature(get_many_mut)]
4621- ///
46224618 /// 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]) {
46244620 /// *a = 413;
46254621 /// *b = 612;
46264622 /// }
46274623 /// assert_eq!(v, &[413, 2, 612]);
46284624 ///
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]) {
46304626 /// a[0] = 8;
46314627 /// b[0] = 88;
46324628 /// b[1] = 888;
46334629 /// }
46344630 /// assert_eq!(v, &[8, 88, 888]);
46354631 ///
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]) {
46374633 /// a[0] = 11;
46384634 /// a[1] = 111;
46394635 /// b[0] = 1;
46404636 /// }
46414637 /// assert_eq!(v, &[1, 11, 111]);
46424638 /// ```
4643- #[ unstable ( feature = "get_many_mut" , issue = "104642 " ) ]
4639+ #[ stable ( feature = "get_many_mut" , since = "CURRENT_RUSTC_VERSION " ) ]
46444640 #[ inline]
4645- pub fn get_many_mut < I , const N : usize > (
4641+ pub fn get_disjoint_mut < I , const N : usize > (
46464642 & mut self ,
46474643 indices : [ I ; N ] ,
4648- ) -> Result < [ & mut I :: Output ; N ] , GetManyMutError >
4644+ ) -> Result < [ & mut I :: Output ; N ] , GetDisjointMutError >
46494645 where
4650- I : GetManyMutIndex + SliceIndex < Self > ,
4646+ I : GetDisjointMutIndex + SliceIndex < Self > ,
46514647 {
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
46544650 // are disjunct and in bounds.
4655- unsafe { Ok ( self . get_many_unchecked_mut ( indices) ) }
4651+ unsafe { Ok ( self . get_disjoint_unchecked_mut ( indices) ) }
46564652 }
46574653
46584654 /// Returns the index that an element reference points to.
@@ -4994,26 +4990,26 @@ impl<T, const N: usize> SlicePattern for [T; N] {
49944990/// This will do `binomial(N + 1, 2) = N * (N + 1) / 2 = 0, 1, 3, 6, 10, ..`
49954991/// comparison operations.
49964992#[ inline]
4997- fn get_many_check_valid < I : GetManyMutIndex , const N : usize > (
4993+ fn get_disjoint_check_valid < I : GetDisjointMutIndex , const N : usize > (
49984994 indices : & [ I ; N ] ,
49994995 len : usize ,
5000- ) -> Result < ( ) , GetManyMutError > {
4996+ ) -> Result < ( ) , GetDisjointMutError > {
50014997 // NB: The optimizer should inline the loops into a sequence
50024998 // of instructions without additional branching.
50034999 for ( i, idx) in indices. iter ( ) . enumerate ( ) {
50045000 if !idx. is_in_bounds ( len) {
5005- return Err ( GetManyMutError :: IndexOutOfBounds ) ;
5001+ return Err ( GetDisjointMutError :: IndexOutOfBounds ) ;
50065002 }
50075003 for idx2 in & indices[ ..i] {
50085004 if idx. is_overlapping ( idx2) {
5009- return Err ( GetManyMutError :: OverlappingIndices ) ;
5005+ return Err ( GetDisjointMutError :: OverlappingIndices ) ;
50105006 }
50115007 }
50125008 }
50135009 Ok ( ( ) )
50145010}
50155011
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 `].
50175013///
50185014/// It indicates one of two possible errors:
50195015/// - An index is out-of-bounds.
@@ -5023,74 +5019,75 @@ fn get_many_check_valid<I: GetManyMutIndex, const N: usize>(
50235019/// # Examples
50245020///
50255021/// ```
5026- /// #![feature(get_many_mut)]
5027- /// use std::slice::GetManyMutError;
5022+ /// use std::slice::GetDisjointMutError;
50285023///
50295024/// 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));
50325027/// ```
5033- #[ unstable ( feature = "get_many_mut" , issue = "104642 " ) ]
5028+ #[ stable ( feature = "get_many_mut" , since = "CURRENT_RUSTC_VERSION " ) ]
50345029#[ derive( Debug , Clone , PartialEq , Eq ) ]
5035- pub enum GetManyMutError {
5030+ pub enum GetDisjointMutError {
50365031 /// An index provided was out-of-bounds for the slice.
50375032 IndexOutOfBounds ,
50385033 /// Two indices provided were overlapping.
50395034 OverlappingIndices ,
50405035}
50415036
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 {
50445039 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
50455040 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" ,
50485043 } ;
50495044 fmt:: Display :: fmt ( msg, f)
50505045 }
50515046}
50525047
5053- mod private_get_many_mut_index {
5048+ mod private_get_disjoint_mut_index {
50545049 use super :: { Range , RangeInclusive , range} ;
50555050
5056- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5051+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50575052 pub trait Sealed { }
50585053
5059- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5054+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50605055 impl Sealed for usize { }
5061- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5056+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50625057 impl Sealed for Range < usize > { }
5063- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5058+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50645059 impl Sealed for RangeInclusive < usize > { }
5065- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5060+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50665061 impl Sealed for range:: Range < usize > { }
5067- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5062+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50685063 impl Sealed for range:: RangeInclusive < usize > { }
50695064}
50705065
5071- /// A helper trait for `<[T]>::get_many_mut ()`.
5066+ /// A helper trait for `<[T]>::get_disjoint_mut ()`.
50725067///
50735068/// # Safety
50745069///
50755070/// If `is_in_bounds()` returns `true` and `is_overlapping()` returns `false`,
50765071/// 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+ {
50795076 /// 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" ) ]
50815078 fn is_in_bounds ( & self , len : usize ) -> bool ;
50825079
50835080 /// Returns `true` if `self` overlaps with `other`.
50845081 ///
50855082 /// Note that we don't consider zero-length ranges to overlap at the beginning or the end,
50865083 /// 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" ) ]
50885085 fn is_overlapping ( & self , other : & Self ) -> bool ;
50895086}
50905087
5091- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5088+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50925089// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5093- unsafe impl GetManyMutIndex for usize {
5090+ unsafe impl GetDisjointMutIndex for usize {
50945091 #[ inline]
50955092 fn is_in_bounds ( & self , len : usize ) -> bool {
50965093 * self < len
@@ -5102,9 +5099,9 @@ unsafe impl GetManyMutIndex for usize {
51025099 }
51035100}
51045101
5105- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5102+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
51065103// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5107- unsafe impl GetManyMutIndex for Range < usize > {
5104+ unsafe impl GetDisjointMutIndex for Range < usize > {
51085105 #[ inline]
51095106 fn is_in_bounds ( & self , len : usize ) -> bool {
51105107 ( self . start <= self . end ) & ( self . end <= len)
@@ -5116,9 +5113,9 @@ unsafe impl GetManyMutIndex for Range<usize> {
51165113 }
51175114}
51185115
5119- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5116+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
51205117// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5121- unsafe impl GetManyMutIndex for RangeInclusive < usize > {
5118+ unsafe impl GetDisjointMutIndex for RangeInclusive < usize > {
51225119 #[ inline]
51235120 fn is_in_bounds ( & self , len : usize ) -> bool {
51245121 ( self . start <= self . end ) & ( self . end < len)
@@ -5130,9 +5127,9 @@ unsafe impl GetManyMutIndex for RangeInclusive<usize> {
51305127 }
51315128}
51325129
5133- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5130+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
51345131// 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 > {
51365133 #[ inline]
51375134 fn is_in_bounds ( & self , len : usize ) -> bool {
51385135 Range :: from ( * self ) . is_in_bounds ( len)
@@ -5144,9 +5141,9 @@ unsafe impl GetManyMutIndex for range::Range<usize> {
51445141 }
51455142}
51465143
5147- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5144+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
51485145// 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 > {
51505147 #[ inline]
51515148 fn is_in_bounds ( & self , len : usize ) -> bool {
51525149 RangeInclusive :: from ( * self ) . is_in_bounds ( len)
0 commit comments