diff options
| author | joboet <jonasboettiger@icloud.com> | 2024-01-13 20:10:00 +0100 |
|---|---|---|
| committer | joboet <jonasboettiger@icloud.com> | 2024-01-13 20:10:00 +0100 |
| commit | fa9a911a57eff5d2cd59eacbffb4e41bc721db2e (patch) | |
| tree | be7dbf9dcc0c9d7639d68111762adbd962e6ee11 /library/core/src | |
| parent | 174e73a3f6df6f96ab453493796e461164dea94a (diff) | |
| download | rust-fa9a911a57eff5d2cd59eacbffb4e41bc721db2e.tar.gz rust-fa9a911a57eff5d2cd59eacbffb4e41bc721db2e.zip | |
libs: use `assert_unchecked` instead of intrinsic
Diffstat (limited to 'library/core/src')
| -rw-r--r-- | library/core/src/alloc/global.rs | 2 | ||||
| -rw-r--r-- | library/core/src/lib.rs | 1 | ||||
| -rw-r--r-- | library/core/src/num/mod.rs | 1 | ||||
| -rw-r--r-- | library/core/src/num/uint_macros.rs | 4 | ||||
| -rw-r--r-- | library/core/src/slice/index.rs | 2 | ||||
| -rw-r--r-- | library/core/src/slice/iter.rs | 2 | ||||
| -rw-r--r-- | library/core/src/slice/iter/macros.rs | 4 | ||||
| -rw-r--r-- | library/core/src/slice/mod.rs | 5 |
8 files changed, 12 insertions, 9 deletions
diff --git a/library/core/src/alloc/global.rs b/library/core/src/alloc/global.rs index c582111701a..a1fff6707bd 100644 --- a/library/core/src/alloc/global.rs +++ b/library/core/src/alloc/global.rs @@ -110,7 +110,7 @@ use crate::ptr; /// ```rust,ignore (unsound and has placeholders) /// drop(Box::new(42)); /// let number_of_heap_allocs = /* call private allocator API */; -/// unsafe { std::intrinsics::assume(number_of_heap_allocs > 0); } +/// unsafe { std::hint::assert_unchecked(number_of_heap_allocs > 0); } /// ``` /// /// Note that the optimizations mentioned above are not the only diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 1a8f245c8be..d0f89efa518 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -131,6 +131,7 @@ #![feature(const_fmt_arguments_new)] #![feature(const_hash)] #![feature(const_heap)] +#![feature(const_hint_assert_unchecked)] #![feature(const_index_range_slice_index)] #![feature(const_int_unchecked_arith)] #![feature(const_intrinsic_forget)] diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 695e87aaabf..2e683592b46 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -3,6 +3,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::ascii; +use crate::hint; use crate::intrinsics; use crate::mem; use crate::ops::{Add, Mul, Sub}; diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 11a53aaf122..62d6015fafe 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -2036,8 +2036,8 @@ macro_rules! uint_impl { // SAFETY: the result is positive and fits in an integer with half as many bits. // Inform the optimizer about it. unsafe { - intrinsics::assume(0 < res); - intrinsics::assume(res < 1 << (Self::BITS / 2)); + hint::assert_unchecked(0 < res); + hint::assert_unchecked(res < 1 << (Self::BITS / 2)); } res 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) } |
