Skip to content

Commit

Permalink
Auto merge of #124498 - tgross35:stabilize-non_null_convenience, r=jh…
Browse files Browse the repository at this point in the history
…pratt

Stabilize `non_null_convenience`

Fully stabilize the following API, including const where applicable:

```rust
impl <T> NonNull<T> {
    pub const unsafe fn offset(self, count: isize) -> Self;
    pub const unsafe fn add(self, count: usize) -> Self;
    pub const unsafe fn sub(self, count: usize) -> Self;
    pub const unsafe fn offset_from(self, origin: NonNull<T>) -> isize;
    pub const unsafe fn read(self) -> T;
    pub unsafe fn read_volatile(self) -> T;
    pub const unsafe fn read_unaligned(self) -> T;
    pub unsafe fn write_volatile(self, val: T);
    pub unsafe fn replace(self, src: T) -> T;
}

impl<T: ?Sized> NonNull<T> {
    pub const unsafe fn byte_offset(self, count: isize) -> Self;
    pub const unsafe fn byte_add(self, count: usize) -> Self;
    pub const unsafe fn byte_sub(self, count: usize) -> Self;
    pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: NonNull<U>) -> isize;
    pub unsafe fn drop_in_place(self);
}
```

Stabilize the following without const:

```rust
impl <T> NonNull<T> {
    // const under `const_intrinsic_copy`
    pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize);
    pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize);
    pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize);

    // const under `const_ptr_write`
    pub const unsafe fn write(self, val: T);
    pub const unsafe fn write_bytes(self, val: u8, count: usize);
    pub const unsafe fn write_unaligned(self, val: T);

    // const under `const_swap`
    pub const unsafe fn swap(self, with: NonNull<T>);

    // const under `const_align_offset`
    pub const fn align_offset(self, align: usize) -> usize;

    // const under `const_pointer_is_aligned`
    pub const fn is_aligned(self) -> bool;
}
```

Left the following unstable:

```rust
impl <T> NonNull<T> {
    // moved gate to `ptr_sub_ptr`
    pub const unsafe fn sub_ptr(self, subtracted: NonNull<T>) -> usize;
}

impl <T: ?Sized> NonNull<T> {
    // moved gate to `pointer_is_aligned_to`
    pub const fn is_aligned_to(self, align: usize) -> bool;
}
```

Fixes: #117691
  • Loading branch information
bors committed Apr 29, 2024
2 parents 1fffb2a + e0f8202 commit 5fe8b69
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 79 deletions.
1 change: 0 additions & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@
#![feature(maybe_uninit_slice)]
#![feature(maybe_uninit_uninit_array)]
#![feature(maybe_uninit_uninit_array_transpose)]
#![feature(non_null_convenience)]
#![feature(panic_internals)]
#![feature(pattern)]
#![feature(ptr_internals)]
Expand Down
1 change: 0 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@
#![feature(isqrt)]
#![feature(link_cfg)]
#![feature(maybe_uninit_uninit_array)]
#![feature(non_null_convenience)]
#![feature(offset_of_enum)]
#![feature(offset_of_nested)]
#![feature(panic_internals)]
Expand Down
Loading

0 comments on commit 5fe8b69

Please sign in to comment.