Skip to content

Commit

Permalink
Rollup merge of rust-lang#132847 - RalfJung:addr-dont-expose, r=Mark-…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
matthiaskrgr authored Nov 12, 2024
2 parents 327a0d7 + 57c7b80 commit e3925fa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4578,8 +4578,8 @@ impl<T> [T] {
panic!("elements are zero-sized");
}

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

let byte_offset = elem_start.wrapping_sub(self_start);

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

let self_start = self.as_ptr() as usize;
let subslice_start = subslice.as_ptr() as usize;
let self_start = self.as_ptr().addr();
let subslice_start = subslice.as_ptr().addr();

let byte_start = subslice_start.wrapping_sub(self_start);

Expand Down

0 comments on commit e3925fa

Please sign in to comment.