Skip to content

Commit ced312f

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 1056a81 commit ced312f

File tree

6 files changed

+98
-103
lines changed

6 files changed

+98
-103
lines changed

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))]

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_many_mut", since = "CURRENT_RUSTC_VERSION")]
1079+
impl Error for crate::slice::GetDisjointMutError {}

core/src/slice/mod.rs

+56-59
Original file line numberDiff line numberDiff line change
@@ -4530,7 +4530,7 @@ impl<T> [T] {
45304530
/// to single elements, while if passed an array of ranges it gives back an array of
45314531
/// mutable references to slices.
45324532
///
4533-
/// For a safe alternative see [`get_many_mut`].
4533+
/// For a safe alternative see [`get_disjoint_mut`].
45344534
///
45354535
/// # Safety
45364536
///
@@ -4540,44 +4540,42 @@ impl<T> [T] {
45404540
/// # Examples
45414541
///
45424542
/// ```
4543-
/// #![feature(get_many_mut)]
4544-
///
45454543
/// let x = &mut [1, 2, 4];
45464544
///
45474545
/// unsafe {
4548-
/// let [a, b] = x.get_many_unchecked_mut([0, 2]);
4546+
/// let [a, b] = x.get_disjoint_unchecked_mut([0, 2]);
45494547
/// *a *= 10;
45504548
/// *b *= 100;
45514549
/// }
45524550
/// assert_eq!(x, &[10, 2, 400]);
45534551
///
45544552
/// unsafe {
4555-
/// let [a, b] = x.get_many_unchecked_mut([0..1, 1..3]);
4553+
/// let [a, b] = x.get_disjoint_unchecked_mut([0..1, 1..3]);
45564554
/// a[0] = 8;
45574555
/// b[0] = 88;
45584556
/// b[1] = 888;
45594557
/// }
45604558
/// assert_eq!(x, &[8, 88, 888]);
45614559
///
45624560
/// unsafe {
4563-
/// let [a, b] = x.get_many_unchecked_mut([1..=2, 0..=0]);
4561+
/// let [a, b] = x.get_disjoint_unchecked_mut([1..=2, 0..=0]);
45644562
/// a[0] = 11;
45654563
/// a[1] = 111;
45664564
/// b[0] = 1;
45674565
/// }
45684566
/// assert_eq!(x, &[1, 11, 111]);
45694567
/// ```
45704568
///
4571-
/// [`get_many_mut`]: slice::get_many_mut
4569+
/// [`get_disjoint_mut`]: slice::get_disjoint_mut
45724570
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
4573-
#[unstable(feature = "get_many_mut", issue = "104642")]
4571+
#[stable(feature = "get_many_mut", since = "CURRENT_RUSTC_VERSION")]
45744572
#[inline]
4575-
pub unsafe fn get_many_unchecked_mut<I, const N: usize>(
4573+
pub unsafe fn get_disjoint_unchecked_mut<I, const N: usize>(
45764574
&mut self,
45774575
indices: [I; N],
45784576
) -> [&mut I::Output; N]
45794577
where
4580-
I: GetManyMutIndex + SliceIndex<Self>,
4578+
I: GetDisjointMutIndex + SliceIndex<Self>,
45814579
{
45824580
// NB: This implementation is written as it is because any variation of
45834581
// `indices.map(|i| self.get_unchecked_mut(i))` would make miri unhappy,
@@ -4616,42 +4614,40 @@ impl<T> [T] {
46164614
/// # Examples
46174615
///
46184616
/// ```
4619-
/// #![feature(get_many_mut)]
4620-
///
46214617
/// let v = &mut [1, 2, 3];
4622-
/// if let Ok([a, b]) = v.get_many_mut([0, 2]) {
4618+
/// if let Ok([a, b]) = v.get_disjoint_mut([0, 2]) {
46234619
/// *a = 413;
46244620
/// *b = 612;
46254621
/// }
46264622
/// assert_eq!(v, &[413, 2, 612]);
46274623
///
4628-
/// if let Ok([a, b]) = v.get_many_mut([0..1, 1..3]) {
4624+
/// if let Ok([a, b]) = v.get_disjoint_mut([0..1, 1..3]) {
46294625
/// a[0] = 8;
46304626
/// b[0] = 88;
46314627
/// b[1] = 888;
46324628
/// }
46334629
/// assert_eq!(v, &[8, 88, 888]);
46344630
///
4635-
/// if let Ok([a, b]) = v.get_many_mut([1..=2, 0..=0]) {
4631+
/// if let Ok([a, b]) = v.get_disjoint_mut([1..=2, 0..=0]) {
46364632
/// a[0] = 11;
46374633
/// a[1] = 111;
46384634
/// b[0] = 1;
46394635
/// }
46404636
/// assert_eq!(v, &[1, 11, 111]);
46414637
/// ```
4642-
#[unstable(feature = "get_many_mut", issue = "104642")]
4638+
#[stable(feature = "get_many_mut", since = "CURRENT_RUSTC_VERSION")]
46434639
#[inline]
4644-
pub fn get_many_mut<I, const N: usize>(
4640+
pub fn get_disjoint_mut<I, const N: usize>(
46454641
&mut self,
46464642
indices: [I; N],
4647-
) -> Result<[&mut I::Output; N], GetManyMutError>
4643+
) -> Result<[&mut I::Output; N], GetDisjointMutError>
46484644
where
4649-
I: GetManyMutIndex + SliceIndex<Self>,
4645+
I: GetDisjointMutIndex + SliceIndex<Self>,
46504646
{
4651-
get_many_check_valid(&indices, self.len())?;
4652-
// SAFETY: The `get_many_check_valid()` call checked that all indices
4647+
get_disjoint_check_valid(&indices, self.len())?;
4648+
// SAFETY: The `get_disjoint_check_valid()` call checked that all indices
46534649
// are disjunct and in bounds.
4654-
unsafe { Ok(self.get_many_unchecked_mut(indices)) }
4650+
unsafe { Ok(self.get_disjoint_unchecked_mut(indices)) }
46554651
}
46564652

46574653
/// Returns the index that an element reference points to.
@@ -4993,26 +4989,26 @@ impl<T, const N: usize> SlicePattern for [T; N] {
49934989
/// This will do `binomial(N + 1, 2) = N * (N + 1) / 2 = 0, 1, 3, 6, 10, ..`
49944990
/// comparison operations.
49954991
#[inline]
4996-
fn get_many_check_valid<I: GetManyMutIndex, const N: usize>(
4992+
fn get_disjoint_check_valid<I: GetDisjointMutIndex, const N: usize>(
49974993
indices: &[I; N],
49984994
len: usize,
4999-
) -> Result<(), GetManyMutError> {
4995+
) -> Result<(), GetDisjointMutError> {
50004996
// NB: The optimizer should inline the loops into a sequence
50014997
// of instructions without additional branching.
50024998
for (i, idx) in indices.iter().enumerate() {
50034999
if !idx.is_in_bounds(len) {
5004-
return Err(GetManyMutError::IndexOutOfBounds);
5000+
return Err(GetDisjointMutError::IndexOutOfBounds);
50055001
}
50065002
for idx2 in &indices[..i] {
50075003
if idx.is_overlapping(idx2) {
5008-
return Err(GetManyMutError::OverlappingIndices);
5004+
return Err(GetDisjointMutError::OverlappingIndices);
50095005
}
50105006
}
50115007
}
50125008
Ok(())
50135009
}
50145010

5015-
/// The error type returned by [`get_many_mut`][`slice::get_many_mut`].
5011+
/// The error type returned by [`get_disjoint_mut`][`slice::get_disjoint_mut`].
50165012
///
50175013
/// It indicates one of two possible errors:
50185014
/// - An index is out-of-bounds.
@@ -5022,74 +5018,75 @@ fn get_many_check_valid<I: GetManyMutIndex, const N: usize>(
50225018
/// # Examples
50235019
///
50245020
/// ```
5025-
/// #![feature(get_many_mut)]
5026-
/// use std::slice::GetManyMutError;
5021+
/// use std::slice::GetDisjointMutError;
50275022
///
50285023
/// let v = &mut [1, 2, 3];
5029-
/// assert_eq!(v.get_many_mut([0, 999]), Err(GetManyMutError::IndexOutOfBounds));
5030-
/// assert_eq!(v.get_many_mut([1, 1]), Err(GetManyMutError::OverlappingIndices));
5024+
/// assert_eq!(v.get_disjoint_mut([0, 999]), Err(GetDisjointMutError::IndexOutOfBounds));
5025+
/// assert_eq!(v.get_disjoint_mut([1, 1]), Err(GetDisjointMutError::OverlappingIndices));
50315026
/// ```
5032-
#[unstable(feature = "get_many_mut", issue = "104642")]
5027+
#[stable(feature = "get_many_mut", since = "CURRENT_RUSTC_VERSION")]
50335028
#[derive(Debug, Clone, PartialEq, Eq)]
5034-
pub enum GetManyMutError {
5029+
pub enum GetDisjointMutError {
50355030
/// An index provided was out-of-bounds for the slice.
50365031
IndexOutOfBounds,
50375032
/// Two indices provided were overlapping.
50385033
OverlappingIndices,
50395034
}
50405035

5041-
#[unstable(feature = "get_many_mut", issue = "104642")]
5042-
impl fmt::Display for GetManyMutError {
5036+
#[stable(feature = "get_many_mut", since = "CURRENT_RUSTC_VERSION")]
5037+
impl fmt::Display for GetDisjointMutError {
50435038
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50445039
let msg = match self {
5045-
GetManyMutError::IndexOutOfBounds => "an index is out of bounds",
5046-
GetManyMutError::OverlappingIndices => "there were overlapping indices",
5040+
GetDisjointMutError::IndexOutOfBounds => "an index is out of bounds",
5041+
GetDisjointMutError::OverlappingIndices => "there were overlapping indices",
50475042
};
50485043
fmt::Display::fmt(msg, f)
50495044
}
50505045
}
50515046

5052-
mod private_get_many_mut_index {
5047+
mod private_get_disjoint_mut_index {
50535048
use super::{Range, RangeInclusive, range};
50545049

5055-
#[unstable(feature = "get_many_mut_helpers", issue = "none")]
5050+
#[unstable(feature = "get_disjoint_mut_helpers", issue = "none")]
50565051
pub trait Sealed {}
50575052

5058-
#[unstable(feature = "get_many_mut_helpers", issue = "none")]
5053+
#[unstable(feature = "get_disjoint_mut_helpers", issue = "none")]
50595054
impl Sealed for usize {}
5060-
#[unstable(feature = "get_many_mut_helpers", issue = "none")]
5055+
#[unstable(feature = "get_disjoint_mut_helpers", issue = "none")]
50615056
impl Sealed for Range<usize> {}
5062-
#[unstable(feature = "get_many_mut_helpers", issue = "none")]
5057+
#[unstable(feature = "get_disjoint_mut_helpers", issue = "none")]
50635058
impl Sealed for RangeInclusive<usize> {}
5064-
#[unstable(feature = "get_many_mut_helpers", issue = "none")]
5059+
#[unstable(feature = "get_disjoint_mut_helpers", issue = "none")]
50655060
impl Sealed for range::Range<usize> {}
5066-
#[unstable(feature = "get_many_mut_helpers", issue = "none")]
5061+
#[unstable(feature = "get_disjoint_mut_helpers", issue = "none")]
50675062
impl Sealed for range::RangeInclusive<usize> {}
50685063
}
50695064

5070-
/// A helper trait for `<[T]>::get_many_mut()`.
5065+
/// A helper trait for `<[T]>::get_disjoint_mut()`.
50715066
///
50725067
/// # Safety
50735068
///
50745069
/// If `is_in_bounds()` returns `true` and `is_overlapping()` returns `false`,
50755070
/// it must be safe to index the slice with the indices.
5076-
#[unstable(feature = "get_many_mut_helpers", issue = "none")]
5077-
pub unsafe trait GetManyMutIndex: Clone + private_get_many_mut_index::Sealed {
5071+
#[unstable(feature = "get_disjoint_mut_helpers", issue = "none")]
5072+
pub unsafe trait GetDisjointMutIndex:
5073+
Clone + private_get_disjoint_mut_index::Sealed
5074+
{
50785075
/// Returns `true` if `self` is in bounds for `len` slice elements.
5079-
#[unstable(feature = "get_many_mut_helpers", issue = "none")]
5076+
#[unstable(feature = "get_disjoint_mut_helpers", issue = "none")]
50805077
fn is_in_bounds(&self, len: usize) -> bool;
50815078

50825079
/// Returns `true` if `self` overlaps with `other`.
50835080
///
50845081
/// Note that we don't consider zero-length ranges to overlap at the beginning or the end,
50855082
/// but do consider them to overlap in the middle.
5086-
#[unstable(feature = "get_many_mut_helpers", issue = "none")]
5083+
#[unstable(feature = "get_disjoint_mut_helpers", issue = "none")]
50875084
fn is_overlapping(&self, other: &Self) -> bool;
50885085
}
50895086

5090-
#[unstable(feature = "get_many_mut_helpers", issue = "none")]
5087+
#[unstable(feature = "get_disjoint_mut_helpers", issue = "none")]
50915088
// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5092-
unsafe impl GetManyMutIndex for usize {
5089+
unsafe impl GetDisjointMutIndex for usize {
50935090
#[inline]
50945091
fn is_in_bounds(&self, len: usize) -> bool {
50955092
*self < len
@@ -5101,9 +5098,9 @@ unsafe impl GetManyMutIndex for usize {
51015098
}
51025099
}
51035100

5104-
#[unstable(feature = "get_many_mut_helpers", issue = "none")]
5101+
#[unstable(feature = "get_disjoint_mut_helpers", issue = "none")]
51055102
// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5106-
unsafe impl GetManyMutIndex for Range<usize> {
5103+
unsafe impl GetDisjointMutIndex for Range<usize> {
51075104
#[inline]
51085105
fn is_in_bounds(&self, len: usize) -> bool {
51095106
(self.start <= self.end) & (self.end <= len)
@@ -5115,9 +5112,9 @@ unsafe impl GetManyMutIndex for Range<usize> {
51155112
}
51165113
}
51175114

5118-
#[unstable(feature = "get_many_mut_helpers", issue = "none")]
5115+
#[unstable(feature = "get_disjoint_mut_helpers", issue = "none")]
51195116
// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5120-
unsafe impl GetManyMutIndex for RangeInclusive<usize> {
5117+
unsafe impl GetDisjointMutIndex for RangeInclusive<usize> {
51215118
#[inline]
51225119
fn is_in_bounds(&self, len: usize) -> bool {
51235120
(self.start <= self.end) & (self.end < len)
@@ -5129,9 +5126,9 @@ unsafe impl GetManyMutIndex for RangeInclusive<usize> {
51295126
}
51305127
}
51315128

5132-
#[unstable(feature = "get_many_mut_helpers", issue = "none")]
5129+
#[unstable(feature = "get_disjoint_mut_helpers", issue = "none")]
51335130
// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5134-
unsafe impl GetManyMutIndex for range::Range<usize> {
5131+
unsafe impl GetDisjointMutIndex for range::Range<usize> {
51355132
#[inline]
51365133
fn is_in_bounds(&self, len: usize) -> bool {
51375134
Range::from(*self).is_in_bounds(len)
@@ -5143,9 +5140,9 @@ unsafe impl GetManyMutIndex for range::Range<usize> {
51435140
}
51445141
}
51455142

5146-
#[unstable(feature = "get_many_mut_helpers", issue = "none")]
5143+
#[unstable(feature = "get_disjoint_mut_helpers", issue = "none")]
51475144
// SAFETY: We implement `is_in_bounds()` and `is_overlapping()` correctly.
5148-
unsafe impl GetManyMutIndex for range::RangeInclusive<usize> {
5145+
unsafe impl GetDisjointMutIndex for range::RangeInclusive<usize> {
51495146
#[inline]
51505147
fn is_in_bounds(&self, len: usize) -> bool {
51515148
RangeInclusive::from(*self).is_in_bounds(len)

coretests/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#![feature(freeze)]
3737
#![feature(future_join)]
3838
#![feature(generic_assert_internals)]
39-
#![feature(get_many_mut)]
4039
#![feature(hasher_prefixfree_extras)]
4140
#![feature(hashmap_internals)]
4241
#![feature(inline_const_pat)]

0 commit comments

Comments
 (0)