Skip to content

Commit 5a9b116

Browse files
authored
Rollup merge of rust-lang#100822 - WaffleLapkin:no_offset_question_mark, r=scottmcm
Replace most uses of `pointer::offset` with `add` and `sub` As PR title says, it replaces `pointer::offset` in compiler and standard library with `pointer::add` and `pointer::sub`. This generally makes code cleaner, easier to grasp and removes (or, well, hides) integer casts. This is generally trivially correct, `.offset(-constant)` is just `.sub(constant)`, `.offset(usized as isize)` is just `.add(usized)`, etc. However in some cases we need to be careful with signs of things. r? ````@scottmcm```` _split off from #100746_
2 parents ee65a10 + bd1ab72 commit 5a9b116

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

example/alloc_system.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ mod platform {
9494
struct Header(*mut u8);
9595
const HEAP_ZERO_MEMORY: DWORD = 0x00000008;
9696
unsafe fn get_header<'a>(ptr: *mut u8) -> &'a mut Header {
97-
&mut *(ptr as *mut Header).offset(-1)
97+
&mut *(ptr as *mut Header).sub(1)
9898
}
9999
unsafe fn align_ptr(ptr: *mut u8, align: usize) -> *mut u8 {
100100
let aligned = ptr.add(align - (ptr as usize & (align - 1)));

0 commit comments

Comments
 (0)