Skip to content

Commit 304ce1b

Browse files
committed
Save another BB by using SubUnchecked instead of a call to arith_offset
Probably reasonable anyway since it more obviously drops provenance.
1 parent f138560 commit 304ce1b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Diff for: core/src/slice/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::iter::{
1111
use crate::marker::PhantomData;
1212
use crate::mem::{self, SizedTypeProperties};
1313
use crate::num::NonZero;
14-
use crate::ptr::{NonNull, null, without_provenance, without_provenance_mut};
14+
use crate::ptr::{NonNull, without_provenance, without_provenance_mut};
1515
use crate::{cmp, fmt};
1616

1717
#[stable(feature = "boxed_slice_into_iter", since = "1.80.0")]

Diff for: core/src/slice/iter/macros.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ macro_rules! iterator {
162162
// SAFETY: Type invariants.
163163
unsafe {
164164
if T::IS_ZST {
165-
let byte_end = end_or_len as *const u8;
166-
if byte_end == null() {
165+
let len = end_or_len.addr();
166+
if len == 0 {
167167
return None;
168168
}
169-
self.end_or_len = byte_end.wrapping_sub(1) as _;
169+
self.end_or_len = without_provenance_mut(len.unchecked_sub(1));
170170
} else {
171-
if ptr == crate::intrinsics::transmute::<*const T, NonNull<T>>(end_or_len) {
171+
if ptr == crate::intrinsics::transmute::<$ptr, NonNull<T>>(end_or_len) {
172172
return None;
173173
}
174174
self.ptr = ptr.add(1);

0 commit comments

Comments
 (0)