Skip to content

Commit cf12732

Browse files
authored
don't duplicate slice panic_bounds_check
1 parent c517a0d commit cf12732

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

library/core/src/slice/mod.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,8 @@ impl<T> [T] {
560560
#[stable(feature = "rust1", since = "1.0.0")]
561561
#[inline]
562562
pub fn swap(&mut self, a: usize, b: usize) {
563-
assert_in_bounds(self.len(), a);
564-
assert_in_bounds(self.len(), b);
563+
let _ = &self[a];
564+
let _ = &self[b];
565565

566566
// SAFETY: we just checked that both `a` and `b` are in bounds
567567
unsafe { self.swap_unchecked(a, b) }
@@ -598,8 +598,8 @@ impl<T> [T] {
598598
pub unsafe fn swap_unchecked(&mut self, a: usize, b: usize) {
599599
#[cfg(debug_assertions)]
600600
{
601-
assert_in_bounds(self.len(), a);
602-
assert_in_bounds(self.len(), b);
601+
let _ = &self[a];
602+
let _ = &self[b];
603603
}
604604

605605
let ptr = self.as_mut_ptr();
@@ -3502,12 +3502,6 @@ impl<T> [T] {
35023502
}
35033503
}
35043504

3505-
fn assert_in_bounds(len: usize, idx: usize) {
3506-
if idx >= len {
3507-
panic!("index out of bounds: the len is {} but the index is {}", len, idx);
3508-
}
3509-
}
3510-
35113505
trait CloneFromSpec<T> {
35123506
fn spec_clone_from(&mut self, src: &[T]);
35133507
}

0 commit comments

Comments
 (0)