From daa40235e3904a810e4084463e62e89b0d593629 Mon Sep 17 00:00:00 2001 From: UjwalReddyKotla <145057116+UjwalReddyKotla@users.noreply.github.com> Date: Fri, 7 Mar 2025 23:57:17 -0500 Subject: [PATCH 1/2] Implement pick[23]_mut via get_disjoint_mut [rustc cleanup] #138196 --- compiler/rustc_index/src/slice.rs | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_index/src/slice.rs b/compiler/rustc_index/src/slice.rs index f17ea9e4b59ad..99d2cd6f29c75 100644 --- a/compiler/rustc_index/src/slice.rs +++ b/compiler/rustc_index/src/slice.rs @@ -118,16 +118,7 @@ impl IndexSlice { /// Panics if `a == b`. #[inline] pub fn pick2_mut(&mut self, a: I, b: I) -> (&mut T, &mut T) { - let (ai, bi) = (a.index(), b.index()); - assert!(ai != bi); - - if ai < bi { - let (c1, c2) = self.raw.split_at_mut(bi); - (&mut c1[ai], &mut c2[0]) - } else { - let (c2, c1) = self.pick2_mut(b, a); - (c1, c2) - } + self.raw.get_disjoint_mut([a.index(), b.index()]).unwrap() } /// Returns mutable references to three distinct elements. @@ -135,12 +126,7 @@ impl IndexSlice { /// Panics if the elements are not distinct. #[inline] pub fn pick3_mut(&mut self, a: I, b: I, c: I) -> (&mut T, &mut T, &mut T) { - let (ai, bi, ci) = (a.index(), b.index(), c.index()); - assert!(ai != bi && bi != ci && ci != ai); - let len = self.raw.len(); - assert!(ai < len && bi < len && ci < len); - let ptr = self.raw.as_mut_ptr(); - unsafe { (&mut *ptr.add(ai), &mut *ptr.add(bi), &mut *ptr.add(ci)) } + self.raw.get_disjoint_mut([a.index(), b.index(), c.index()]).unwrap() } #[inline] From dae0cad8bd7871afda91cd425d5a6cc935b8248d Mon Sep 17 00:00:00 2001 From: UjwalReddyKotla <145057116+UjwalReddyKotla@users.noreply.github.com> Date: Fri, 7 Mar 2025 23:58:29 -0500 Subject: [PATCH 2/2] Implement pick[23]_mut via get_disjoint_mut [rustc cleanup] #138196 --- compiler/rustc_index/src/slice.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_index/src/slice.rs b/compiler/rustc_index/src/slice.rs index 99d2cd6f29c75..5cdeee0fa47d2 100644 --- a/compiler/rustc_index/src/slice.rs +++ b/compiler/rustc_index/src/slice.rs @@ -118,7 +118,7 @@ impl IndexSlice { /// Panics if `a == b`. #[inline] pub fn pick2_mut(&mut self, a: I, b: I) -> (&mut T, &mut T) { - self.raw.get_disjoint_mut([a.index(), b.index()]).unwrap() + self.raw.get_disjoint_mut([a.index(), b.index()]).unwrap().into() } /// Returns mutable references to three distinct elements. @@ -126,7 +126,7 @@ impl IndexSlice { /// Panics if the elements are not distinct. #[inline] pub fn pick3_mut(&mut self, a: I, b: I, c: I) -> (&mut T, &mut T, &mut T) { - self.raw.get_disjoint_mut([a.index(), b.index(), c.index()]).unwrap() + self.raw.get_disjoint_mut([a.index(), b.index(), c.index()]).unwrap().into() } #[inline]