]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Auto merge of #95643 - WaffleLapkin:ptr_convenience, r=joshtriplett
authorbors <bors@rust-lang.org>
Wed, 18 May 2022 23:18:03 +0000 (23:18 +0000)
committerbors <bors@rust-lang.org>
Wed, 18 May 2022 23:18:03 +0000 (23:18 +0000)
commitd8a3fc4d71bae720cc2534ff5b97164f47622e12
tree683bdc9c71844589da8f028471e762eb03d77dd3
parentcd282d7f75da9080fda0f1740a729516e7fbec68
parent03d45699390421d6a27f5ae2dc10077b38d950fe
Auto merge of #95643 - WaffleLapkin:ptr_convenience, r=joshtriplett

Add convenience byte offset/check align functions to pointers

This PR adds the following APIs:
```rust
impl *const T {
    // feature gates `pointer_byte_offsets` and `const_pointer_byte_offsets
    pub const unsafe fn byte_offset(self, count: isize) -> Self;
    pub const fn wrapping_byte_offset(self, count: isize) -> Self;
    pub const unsafe fn byte_offset_from(self, origin: *const T) -> isize;
    pub const unsafe fn byte_add(self, count: usize) -> Self;
    pub const unsafe fn byte_sub(self, count: usize) -> Self;
    pub const fn wrapping_byte_add(self, count: usize) -> Self;
    pub const fn wrapping_byte_sub(self, count: usize) -> Self;

    // feature gate `pointer_is_aligned`
    pub fn is_aligned(self) -> bool where T: Sized;
    pub fn is_aligned_to(self, align: usize) -> bool;
}
// ... and the same for` *mut T`
```

Note that all functions except `is_aligned` do **not** require `T: Sized` as their pointee-sized-offset counterparts.

cc `@oli-obk` (you may want to check that I've correctly placed `const`s)
cc `@RalfJung`