Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e3925fa

Browse files
authoredNov 12, 2024
Rollup merge of rust-lang#132847 - RalfJung:addr-dont-expose, r=Mark-Simulacrum
elem_offset / subslice_range: use addr() instead of 'as usize' There's no reason to use ptr-to-int casts with their subtle semantics here.
2 parents 327a0d7 + 57c7b80 commit e3925fa

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎core/src/slice/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4578,8 +4578,8 @@ impl<T> [T] {
45784578
panic!("elements are zero-sized");
45794579
}
45804580

4581-
let self_start = self.as_ptr() as usize;
4582-
let elem_start = element as *const T as usize;
4581+
let self_start = self.as_ptr().addr();
4582+
let elem_start = ptr::from_ref(element).addr();
45834583

45844584
let byte_offset = elem_start.wrapping_sub(self_start);
45854585

@@ -4631,8 +4631,8 @@ impl<T> [T] {
46314631
panic!("elements are zero-sized");
46324632
}
46334633

4634-
let self_start = self.as_ptr() as usize;
4635-
let subslice_start = subslice.as_ptr() as usize;
4634+
let self_start = self.as_ptr().addr();
4635+
let subslice_start = subslice.as_ptr().addr();
46364636

46374637
let byte_start = subslice_start.wrapping_sub(self_start);
46384638

0 commit comments

Comments
 (0)
Failed to load comments.