about summary refs log tree commit diff
path: root/library/core/src/slice
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2025-02-13 22:28:29 -0800
committerScott McMurray <scottmcm@users.noreply.github.com>2025-02-14 22:24:27 -0800
commit3a62c70051e40fbcfc7e5b9ad60cb9cfc4dddcee (patch)
treec80b9645f00035a33413948ffc463f923af9b5f2 /library/core/src/slice
parentaede8f5fbff92bd1b257685c2e654a9bdf3a021f (diff)
downloadrust-3a62c70051e40fbcfc7e5b9ad60cb9cfc4dddcee.tar.gz
rust-3a62c70051e40fbcfc7e5b9ad60cb9cfc4dddcee.zip
Save another BB by using `SubUnchecked` instead of a call to `arith_offset`
Probably reasonable anyway since it more obviously drops provenance.
Diffstat (limited to 'library/core/src/slice')
-rw-r--r--library/core/src/slice/iter.rs2
-rw-r--r--library/core/src/slice/iter/macros.rs8
2 files changed, 5 insertions, 5 deletions
diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs
index 5a87f1327dd..a687ed7129d 100644
--- a/library/core/src/slice/iter.rs
+++ b/library/core/src/slice/iter.rs
@@ -11,7 +11,7 @@ use crate::iter::{
 use crate::marker::PhantomData;
 use crate::mem::{self, SizedTypeProperties};
 use crate::num::NonZero;
-use crate::ptr::{NonNull, null, without_provenance, without_provenance_mut};
+use crate::ptr::{NonNull, without_provenance, without_provenance_mut};
 use crate::{cmp, fmt};
 
 #[stable(feature = "boxed_slice_into_iter", since = "1.80.0")]
diff --git a/library/core/src/slice/iter/macros.rs b/library/core/src/slice/iter/macros.rs
index 74dfb8634f2..101f3157651 100644
--- a/library/core/src/slice/iter/macros.rs
+++ b/library/core/src/slice/iter/macros.rs
@@ -162,13 +162,13 @@ macro_rules! iterator {
                 // SAFETY: Type invariants.
                 unsafe {
                     if T::IS_ZST {
-                        let byte_end = end_or_len as *const u8;
-                        if byte_end == null() {
+                        let len = end_or_len.addr();
+                        if len == 0 {
                             return None;
                         }
-                        self.end_or_len = byte_end.wrapping_sub(1) as _;
+                        self.end_or_len = without_provenance_mut(len.unchecked_sub(1));
                     } else {
-                        if ptr == crate::intrinsics::transmute::<*const T, NonNull<T>>(end_or_len) {
+                        if ptr == crate::intrinsics::transmute::<$ptr, NonNull<T>>(end_or_len) {
                             return None;
                         }
                         self.ptr = ptr.add(1);