@@ -4515,7 +4515,7 @@ impl<T> [T] {
45154515 /// to single elements, while if passed an array of ranges it gives back an array of
45164516 /// mutable references to slices.
45174517 ///
4518- /// For a safe alternative see [`get_many_mut `].
4518+ /// For a safe alternative see [`get_disjoint_mut `].
45194519 ///
45204520 /// # Safety
45214521 ///
@@ -4525,44 +4525,42 @@ impl<T> [T] {
45254525 /// # Examples
45264526 ///
45274527 /// ```
4528- /// #![feature(get_many_mut)]
4529- ///
45304528 /// let x = &mut [1, 2, 4];
45314529 ///
45324530 /// unsafe {
4533- /// let [a, b] = x.get_many_unchecked_mut ([0, 2]);
4531+ /// let [a, b] = x.get_disjoint_unchecked_mut ([0, 2]);
45344532 /// *a *= 10;
45354533 /// *b *= 100;
45364534 /// }
45374535 /// assert_eq!(x, &[10, 2, 400]);
45384536 ///
45394537 /// 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]);
45414539 /// a[0] = 8;
45424540 /// b[0] = 88;
45434541 /// b[1] = 888;
45444542 /// }
45454543 /// assert_eq!(x, &[8, 88, 888]);
45464544 ///
45474545 /// 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]);
45494547 /// a[0] = 11;
45504548 /// a[1] = 111;
45514549 /// b[0] = 1;
45524550 /// }
45534551 /// assert_eq!(x, &[1, 11, 111]);
45544552 /// ```
45554553 ///
4556- /// [`get_many_mut `]: slice::get_many_mut
4554+ /// [`get_disjoint_mut `]: slice::get_disjoint_mut
45574555 /// [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 " ) ]
45594557 #[ 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 > (
45614559 & mut self ,
45624560 indices : [ I ; N ] ,
45634561 ) -> [ & mut I :: Output ; N ]
45644562 where
4565- I : GetManyMutIndex + SliceIndex < Self > ,
4563+ I : GetDisjointMutIndex + SliceIndex < Self > ,
45664564 {
45674565 // NB: This implementation is written as it is because any variation of
45684566 // `indices.map(|i| self.get_unchecked_mut(i))` would make miri unhappy,
@@ -4601,42 +4599,40 @@ impl<T> [T] {
46014599 /// # Examples
46024600 ///
46034601 /// ```
4604- /// #![feature(get_many_mut)]
4605- ///
46064602 /// 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]) {
46084604 /// *a = 413;
46094605 /// *b = 612;
46104606 /// }
46114607 /// assert_eq!(v, &[413, 2, 612]);
46124608 ///
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]) {
46144610 /// a[0] = 8;
46154611 /// b[0] = 88;
46164612 /// b[1] = 888;
46174613 /// }
46184614 /// assert_eq!(v, &[8, 88, 888]);
46194615 ///
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]) {
46214617 /// a[0] = 11;
46224618 /// a[1] = 111;
46234619 /// b[0] = 1;
46244620 /// }
46254621 /// assert_eq!(v, &[1, 11, 111]);
46264622 /// ```
4627- #[ unstable ( feature = "get_many_mut " , issue = "104642 " ) ]
4623+ #[ stable ( feature = "get_disjoint_mut " , since = "CURRENT_RUSTC_VERSION " ) ]
46284624 #[ inline]
4629- pub fn get_many_mut < I , const N : usize > (
4625+ pub fn get_disjoint_mut < I , const N : usize > (
46304626 & mut self ,
46314627 indices : [ I ; N ] ,
4632- ) -> Result < [ & mut I :: Output ; N ] , GetManyMutError >
4628+ ) -> Result < [ & mut I :: Output ; N ] , GetDisjointMutError >
46334629 where
4634- I : GetManyMutIndex + SliceIndex < Self > ,
4630+ I : GetDisjointMutIndex + SliceIndex < Self > ,
46354631 {
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
46384634 // are disjunct and in bounds.
4639- unsafe { Ok ( self . get_many_unchecked_mut ( indices) ) }
4635+ unsafe { Ok ( self . get_disjoint_unchecked_mut ( indices) ) }
46404636 }
46414637
46424638 /// Returns the index that an element reference points to.
@@ -4977,26 +4973,26 @@ impl<T, const N: usize> SlicePattern for [T; N] {
49774973/// This will do `binomial(N + 1, 2) = N * (N + 1) / 2 = 0, 1, 3, 6, 10, ..`
49784974/// comparison operations.
49794975#[ inline]
4980- fn get_many_check_valid < I : GetManyMutIndex , const N : usize > (
4976+ fn get_disjoint_check_valid < I : GetDisjointMutIndex , const N : usize > (
49814977 indices : & [ I ; N ] ,
49824978 len : usize ,
4983- ) -> Result < ( ) , GetManyMutError > {
4979+ ) -> Result < ( ) , GetDisjointMutError > {
49844980 // NB: The optimizer should inline the loops into a sequence
49854981 // of instructions without additional branching.
49864982 for ( i, idx) in indices. iter ( ) . enumerate ( ) {
49874983 if !idx. is_in_bounds ( len) {
4988- return Err ( GetManyMutError :: IndexOutOfBounds ) ;
4984+ return Err ( GetDisjointMutError :: IndexOutOfBounds ) ;
49894985 }
49904986 for idx2 in & indices[ ..i] {
49914987 if idx. is_overlapping ( idx2) {
4992- return Err ( GetManyMutError :: OverlappingIndices ) ;
4988+ return Err ( GetDisjointMutError :: OverlappingIndices ) ;
49934989 }
49944990 }
49954991 }
49964992 Ok ( ( ) )
49974993}
49984994
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 `].
50004996///
50014997/// It indicates one of two possible errors:
50024998/// - An index is out-of-bounds.
@@ -5006,74 +5002,75 @@ fn get_many_check_valid<I: GetManyMutIndex, const N: usize>(
50065002/// # Examples
50075003///
50085004/// ```
5009- /// #![feature(get_many_mut)]
5010- /// use std::slice::GetManyMutError;
5005+ /// use std::slice::GetDisjointMutError;
50115006///
50125007/// 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));
50155010/// ```
5016- #[ unstable ( feature = "get_many_mut " , issue = "104642 " ) ]
5011+ #[ stable ( feature = "get_disjoint_mut " , since = "CURRENT_RUSTC_VERSION " ) ]
50175012#[ derive( Debug , Clone , PartialEq , Eq ) ]
5018- pub enum GetManyMutError {
5013+ pub enum GetDisjointMutError {
50195014 /// An index provided was out-of-bounds for the slice.
50205015 IndexOutOfBounds ,
50215016 /// Two indices provided were overlapping.
50225017 OverlappingIndices ,
50235018}
50245019
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 {
50275022 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
50285023 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" ,
50315026 } ;
50325027 fmt:: Display :: fmt ( msg, f)
50335028 }
50345029}
50355030
5036- mod private_get_many_mut_index {
5031+ mod private_get_disjoint_mut_index {
50375032 use super :: { Range , RangeInclusive , range} ;
50385033
5039- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5034+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50405035 pub trait Sealed { }
50415036
5042- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5037+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50435038 impl Sealed for usize { }
5044- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5039+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50455040 impl Sealed for Range < usize > { }
5046- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5041+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50475042 impl Sealed for RangeInclusive < usize > { }
5048- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5043+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50495044 impl Sealed for range:: Range < usize > { }
5050- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5045+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50515046 impl Sealed for range:: RangeInclusive < usize > { }
50525047}
50535048
5054- /// A helper trait for `<[T]>::get_many_mut ()`.
5049+ /// A helper trait for `<[T]>::get_disjoint_mut ()`.
50555050///
50565051/// # Safety
50575052///
50585053/// If `is_in_bounds()` returns `true` and `is_overlapping()` returns `false`,
50595054/// 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+ {
50625059 /// 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" ) ]
50645061 fn is_in_bounds ( & self , len : usize ) -> bool ;
50655062
50665063 /// Returns `true` if `self` overlaps with `other`.
50675064 ///
50685065 /// Note that we don't consider zero-length ranges to overlap at the beginning or the end,
50695066 /// 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" ) ]
50715068 fn is_overlapping ( & self , other : & Self ) -> bool ;
50725069}
50735070
5074- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5071+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50755072// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5076- unsafe impl GetManyMutIndex for usize {
5073+ unsafe impl GetDisjointMutIndex for usize {
50775074 #[ inline]
50785075 fn is_in_bounds ( & self , len : usize ) -> bool {
50795076 * self < len
@@ -5085,9 +5082,9 @@ unsafe impl GetManyMutIndex for usize {
50855082 }
50865083}
50875084
5088- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5085+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
50895086// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5090- unsafe impl GetManyMutIndex for Range < usize > {
5087+ unsafe impl GetDisjointMutIndex for Range < usize > {
50915088 #[ inline]
50925089 fn is_in_bounds ( & self , len : usize ) -> bool {
50935090 ( self . start <= self . end ) & ( self . end <= len)
@@ -5099,9 +5096,9 @@ unsafe impl GetManyMutIndex for Range<usize> {
50995096 }
51005097}
51015098
5102- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5099+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
51035100// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5104- unsafe impl GetManyMutIndex for RangeInclusive < usize > {
5101+ unsafe impl GetDisjointMutIndex for RangeInclusive < usize > {
51055102 #[ inline]
51065103 fn is_in_bounds ( & self , len : usize ) -> bool {
51075104 ( self . start <= self . end ) & ( self . end < len)
@@ -5113,9 +5110,9 @@ unsafe impl GetManyMutIndex for RangeInclusive<usize> {
51135110 }
51145111}
51155112
5116- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5113+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
51175114// 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 > {
51195116 #[ inline]
51205117 fn is_in_bounds ( & self , len : usize ) -> bool {
51215118 Range :: from ( * self ) . is_in_bounds ( len)
@@ -5127,9 +5124,9 @@ unsafe impl GetManyMutIndex for range::Range<usize> {
51275124 }
51285125}
51295126
5130- #[ unstable( feature = "get_many_mut_helpers " , issue = "none" ) ]
5127+ #[ unstable( feature = "get_disjoint_mut_helpers " , issue = "none" ) ]
51315128// 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 > {
51335130 #[ inline]
51345131 fn is_in_bounds ( & self , len : usize ) -> bool {
51355132 RangeInclusive :: from ( * self ) . is_in_bounds ( len)
0 commit comments