Skip to content

Commit daa4023

Browse files
Implement pick[23]_mut via get_disjoint_mut [rustc cleanup] rust-lang#138196
1 parent f5a1ef7 commit daa4023

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

compiler/rustc_index/src/slice.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,29 +118,15 @@ impl<I: Idx, T> IndexSlice<I, T> {
118118
/// Panics if `a == b`.
119119
#[inline]
120120
pub fn pick2_mut(&mut self, a: I, b: I) -> (&mut T, &mut T) {
121-
let (ai, bi) = (a.index(), b.index());
122-
assert!(ai != bi);
123-
124-
if ai < bi {
125-
let (c1, c2) = self.raw.split_at_mut(bi);
126-
(&mut c1[ai], &mut c2[0])
127-
} else {
128-
let (c2, c1) = self.pick2_mut(b, a);
129-
(c1, c2)
130-
}
121+
self.raw.get_disjoint_mut([a.index(), b.index()]).unwrap()
131122
}
132123

133124
/// Returns mutable references to three distinct elements.
134125
///
135126
/// Panics if the elements are not distinct.
136127
#[inline]
137128
pub fn pick3_mut(&mut self, a: I, b: I, c: I) -> (&mut T, &mut T, &mut T) {
138-
let (ai, bi, ci) = (a.index(), b.index(), c.index());
139-
assert!(ai != bi && bi != ci && ci != ai);
140-
let len = self.raw.len();
141-
assert!(ai < len && bi < len && ci < len);
142-
let ptr = self.raw.as_mut_ptr();
143-
unsafe { (&mut *ptr.add(ai), &mut *ptr.add(bi), &mut *ptr.add(ci)) }
129+
self.raw.get_disjoint_mut([a.index(), b.index(), c.index()]).unwrap()
144130
}
145131

146132
#[inline]

0 commit comments

Comments
 (0)