about summary refs log tree commit diff
path: root/library/core/src/slice
diff options
context:
space:
mode:
authorjoboet <jonasboettiger@icloud.com>2024-01-13 20:10:00 +0100
committerjoboet <jonasboettiger@icloud.com>2024-01-13 20:10:00 +0100
commitfa9a911a57eff5d2cd59eacbffb4e41bc721db2e (patch)
treebe7dbf9dcc0c9d7639d68111762adbd962e6ee11 /library/core/src/slice
parent174e73a3f6df6f96ab453493796e461164dea94a (diff)
downloadrust-fa9a911a57eff5d2cd59eacbffb4e41bc721db2e.tar.gz
rust-fa9a911a57eff5d2cd59eacbffb4e41bc721db2e.zip
libs: use `assert_unchecked` instead of intrinsic
Diffstat (limited to 'library/core/src/slice')
-rw-r--r--library/core/src/slice/index.rs2
-rw-r--r--library/core/src/slice/iter.rs2
-rw-r--r--library/core/src/slice/iter/macros.rs4
-rw-r--r--library/core/src/slice/mod.rs5
4 files changed, 7 insertions, 6 deletions
diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs
index 373b4aee47a..fb9be396eab 100644
--- a/library/core/src/slice/index.rs
+++ b/library/core/src/slice/index.rs
@@ -234,7 +234,7 @@ unsafe impl<T> SliceIndex<[T]> for usize {
         // `self` is in bounds of `slice` so `self` cannot overflow an `isize`,
         // so the call to `add` is safe.
         unsafe {
-            crate::intrinsics::assume(self < slice.len());
+            crate::hint::assert_unchecked(self < slice.len());
             slice.as_ptr().add(self)
         }
     }
diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs
index 3d58afd26ea..e1d19fef35f 100644
--- a/library/core/src/slice/iter.rs
+++ b/library/core/src/slice/iter.rs
@@ -6,7 +6,7 @@ mod macros;
 use crate::cmp;
 use crate::cmp::Ordering;
 use crate::fmt;
-use crate::intrinsics::assume;
+use crate::hint::assert_unchecked;
 use crate::iter::{
     FusedIterator, TrustedLen, TrustedRandomAccess, TrustedRandomAccessNoCoerce, UncheckedIterator,
 };
diff --git a/library/core/src/slice/iter/macros.rs b/library/core/src/slice/iter/macros.rs
index 95bcd123b82..fc6af45fb90 100644
--- a/library/core/src/slice/iter/macros.rs
+++ b/library/core/src/slice/iter/macros.rs
@@ -338,7 +338,7 @@ macro_rules! iterator {
                     if predicate(x) {
                         // SAFETY: we are guaranteed to be in bounds by the loop invariant:
                         // when `i >= n`, `self.next()` returns `None` and the loop breaks.
-                        unsafe { assume(i < n) };
+                        unsafe { assert_unchecked(i < n) };
                         return Some(i);
                     }
                     i += 1;
@@ -361,7 +361,7 @@ macro_rules! iterator {
                     if predicate(x) {
                         // SAFETY: `i` must be lower than `n` since it starts at `n`
                         // and is only decreasing.
-                        unsafe { assume(i < n) };
+                        unsafe { assert_unchecked(i < n) };
                         return Some(i);
                     }
                 }
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs
index 5edc89e4cb5..e971f933570 100644
--- a/library/core/src/slice/mod.rs
+++ b/library/core/src/slice/mod.rs
@@ -8,6 +8,7 @@
 
 use crate::cmp::Ordering::{self, Equal, Greater, Less};
 use crate::fmt;
+use crate::hint;
 use crate::intrinsics::exact_div;
 use crate::mem::{self, SizedTypeProperties};
 use crate::num::NonZeroUsize;
@@ -2850,7 +2851,7 @@ impl<T> [T] {
             right = if cmp == Greater { mid } else { right };
             if cmp == Equal {
                 // SAFETY: same as the `get_unchecked` above
-                unsafe { crate::intrinsics::assume(mid < self.len()) };
+                unsafe { hint::assert_unchecked(mid < self.len()) };
                 return Ok(mid);
             }
 
@@ -2859,7 +2860,7 @@ impl<T> [T] {
 
         // SAFETY: directly true from the overall invariant.
         // Note that this is `<=`, unlike the assume in the `Ok` path.
-        unsafe { crate::intrinsics::assume(left <= self.len()) };
+        unsafe { hint::assert_unchecked(left <= self.len()) };
         Err(left)
     }