diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-08-21 16:54:07 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-21 16:54:07 +0200 |
| commit | 5a9b11648ff069954b27f07e8fc7debdd013b8d8 (patch) | |
| tree | f11b604569225f497c41bbf60500e7c987a2a587 | |
| parent | ee65a1018f54669b17c97bad979edfea1accafbf (diff) | |
| parent | bd1ab724064f2bcc59ddc6157d6cae9ca344939b (diff) | |
| download | rust-5a9b11648ff069954b27f07e8fc7debdd013b8d8.tar.gz rust-5a9b11648ff069954b27f07e8fc7debdd013b8d8.zip | |
Rollup merge of #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_
| -rw-r--r-- | example/alloc_system.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/example/alloc_system.rs b/example/alloc_system.rs index cf95c89bc31..50261c19397 100644 --- a/example/alloc_system.rs +++ b/example/alloc_system.rs @@ -94,7 +94,7 @@ mod platform { struct Header(*mut u8); const HEAP_ZERO_MEMORY: DWORD = 0x00000008; unsafe fn get_header<'a>(ptr: *mut u8) -> &'a mut Header { - &mut *(ptr as *mut Header).offset(-1) + &mut *(ptr as *mut Header).sub(1) } unsafe fn align_ptr(ptr: *mut u8, align: usize) -> *mut u8 { let aligned = ptr.add(align - (ptr as usize & (align - 1))); |
