Skip to content

Commit 1fd41a9

Browse files
committed
Stabilize get_many_mut as get_disjoint_mut
* Renames the methods: * `get_many_mut` -> `get_disjoint_mut` * `get_many_unchecked_mut` -> `get_disjoint_unchecked_mut` * Does not rename the feature flag: `get_many_mut` * Marks the feature as stable * Renames some helper stuff: * `GetManyMutError` -> `GetDisjointMutError` * `GetManyMutIndex` -> `GetDisjointMutIndex` * `get_many_mut_helpers` -> `get_disjoint_mut_helpers` * `get_many_check_valid` -> `get_disjoint_check_valid` This only touches slice methods. HashMap's methods and feature gates are not renamed here (nor are they stabilized).
1 parent b2728d5 commit 1fd41a9

File tree

6 files changed

+98
-103
lines changed

6 files changed

+98
-103
lines changed

library/alloc/src/slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub use core::slice::ArrayChunksMut;
2727
pub use core::slice::ArrayWindows;
2828
#[stable(feature = "inherent_ascii_escape", since = "1.60.0")]
2929
pub use core::slice::EscapeAscii;
30-
#[unstable(feature = "get_many_mut", issue = "104642")]
31-
pub use core::slice::GetManyMutError;
30+
#[stable(feature = "get_many_mut", since = "CURRENT_RUSTC_VERSION")]
31+
pub use core::slice::GetDisjointMutError;
3232
#[stable(feature = "slice_get_slice", since = "1.28.0")]
3333
pub use core::slice::SliceIndex;
3434
#[cfg(not(no_global_oom_handling))]

library/core/src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1075,5 +1075,5 @@ impl Error for crate::time::TryFromFloatSecsError {}
10751075
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
10761076
impl Error for crate::ffi::FromBytesUntilNulError {}
10771077

1078-
#[unstable(feature = "get_many_mut", issue = "104642")]
1079-
impl Error for crate::slice::GetManyMutError {}
1078+
#[stable(feature = "get_disjoint_mut", since = "CURRENT_RUSTC_VERSION")]
1079+
impl Error for crate::slice::GetDisjointMutError {}

library/core/src/slice/mod.rs

+56-59
Original file line numberDiff line numberDiff line change
@@ -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)

library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#![feature(freeze)]
3636
#![feature(future_join)]
3737
#![feature(generic_assert_internals)]
38-
#![feature(get_many_mut)]
3938
#![feature(hasher_prefixfree_extras)]
4039
#![feature(hashmap_internals)]
4140
#![feature(inline_const_pat)]

0 commit comments

Comments
 (0)