diff options
| author | Ibraheem Ahmed <ibrah1440@gmail.com> | 2021-10-14 09:31:34 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-14 09:31:34 -0400 |
| commit | cf12732a38a2c038c8cbd5e0266cb38c43cb0c5d (patch) | |
| tree | 3a87a8771eb5ca06eadb0e9f4046fec0f11c9179 | |
| parent | c517a0de3e8d7d6a85b6f47f0ae8c8988311e288 (diff) | |
| download | rust-cf12732a38a2c038c8cbd5e0266cb38c43cb0c5d.tar.gz rust-cf12732a38a2c038c8cbd5e0266cb38c43cb0c5d.zip | |
don't duplicate slice `panic_bounds_check`
| -rw-r--r-- | library/core/src/slice/mod.rs | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 8108d52071b..c0e0589d5ed 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -560,8 +560,8 @@ impl<T> [T] { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn swap(&mut self, a: usize, b: usize) { - assert_in_bounds(self.len(), a); - assert_in_bounds(self.len(), b); + let _ = &self[a]; + let _ = &self[b]; // SAFETY: we just checked that both `a` and `b` are in bounds unsafe { self.swap_unchecked(a, b) } @@ -598,8 +598,8 @@ impl<T> [T] { pub unsafe fn swap_unchecked(&mut self, a: usize, b: usize) { #[cfg(debug_assertions)] { - assert_in_bounds(self.len(), a); - assert_in_bounds(self.len(), b); + let _ = &self[a]; + let _ = &self[b]; } let ptr = self.as_mut_ptr(); @@ -3502,12 +3502,6 @@ impl<T> [T] { } } -fn assert_in_bounds(len: usize, idx: usize) { - if idx >= len { - panic!("index out of bounds: the len is {} but the index is {}", len, idx); - } -} - trait CloneFromSpec<T> { fn spec_clone_from(&mut self, src: &[T]); } |
