Skip to content

Tracking Issue for convenience methods on NonNull #117691

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
2 of 4 tasks
WaffleLapkin opened this issue Nov 7, 2023 · 7 comments · Fixed by #124498
Closed
2 of 4 tasks

Tracking Issue for convenience methods on NonNull #117691

WaffleLapkin opened this issue Nov 7, 2023 · 7 comments · Fixed by #124498
Labels
A-raw-pointers Area: raw pointers, MaybeUninit, NonNull C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@WaffleLapkin
Copy link
Member

WaffleLapkin commented Nov 7, 2023

Feature gate: #![feature(non_null_convenience)]

This is a tracking issue for convenience methods on NonNull.

Public API

// core::ptr

impl<T: Sized> NonNull<T> {
    pub const unsafe fn offset(self, count: isize) -> NonNull<T>;
    pub const unsafe fn add(self, count: usize) -> NonNull<T>;
    pub const unsafe fn sub(self, count: usize) -> NonNull<T>;

    pub const unsafe fn offset_from(self, origin: NonNull<T>) -> isize;
    pub const unsafe fn sub_ptr(self, subtracted: NonNull<T>) -> usize;

    pub const unsafe fn read(self) -> T;
    pub unsafe fn read_volatile(self) -> T;
    pub const unsafe fn read_unaligned(self) -> T;

    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);
    pub const unsafe fn write(self, val: T); 
    pub const unsafe fn write_bytes(self, val: u8, count: usize);
    pub unsafe fn write_volatile(self, val: T);
    pub const unsafe fn write_unaligned(self, val: T);
    pub unsafe fn replace(self, src: T) -> T;
    pub const unsafe fn swap(self, with: NonNull<T>);

    pub const fn align_offset(self, align: usize) -> usize;
    pub const fn is_aligned(self) -> bool;    
}
    
impl<T: ?Sized> NonNull<T> {
    pub const unsafe fn byte_offset(self, count: isize) -> NonNull<T>;
    pub const unsafe fn byte_add(self, count: usize) -> NonNull<T>;
    pub const unsafe fn byte_sub(self, count: usize) -> NonNull<T>;

    pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: NonNull<U>) -> isize;

    pub unsafe fn drop_in_place(self);

    pub const fn is_aligned_to(self, align: usize) -> bool;
}

(I'll fill the API once PR is merged, stand-by...)

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@WaffleLapkin WaffleLapkin added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC A-raw-pointers Area: raw pointers, MaybeUninit, NonNull labels Nov 7, 2023
Andy-Python-Programmer added a commit to aero-os/crabnet that referenced this issue Mar 24, 2024
* Remove the pointer extension trait for `NonNull` as of the `non_null_convenience` feature.
  CC: rust-lang/rust#117691
* Update the test stderr files, to match with the new error style.

Signed-off-by: Anhad Singh <andypythonappdeveloper@gmail.com>
@tgross35
Copy link
Contributor

These haven't been around super long but seem uncontroversial. Any opposition to moving toward stabilization?

@Amanieu
Copy link
Member

Amanieu commented Apr 17, 2024

This exposes methods on NonNull that are also available on raw pointer types, which makes NonNull more ergonomic to use.

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Apr 17, 2024

Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Apr 17, 2024
@dtolnay
Copy link
Member

dtolnay commented Apr 17, 2024

Please make sure is_aligned_to is not included in the stabilization. That's unstable on raw pointers still.

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Apr 18, 2024
@rfcbot
Copy link
Collaborator

rfcbot commented Apr 18, 2024

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Apr 28, 2024
@rfcbot
Copy link
Collaborator

rfcbot commented Apr 28, 2024

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

tgross35 added a commit to tgross35/rust that referenced this issue Apr 28, 2024
Fully stabilize the following API, including const where applicable:

    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:

    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:

    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> {
        pub const fn is_aligned_to(self, align: usize) -> bool;
    }

Fixes: rust-lang#117691
@tgross35
Copy link
Contributor

Candidate PR: #124498

bors added a commit to rust-lang-ci/rust that referenced this issue Apr 28, 2024
…nce, r=jhpratt

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: rust-lang#117691
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 29, 2024
…nce, r=jhpratt

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: rust-lang#117691
@bors bors closed this as completed in e0f8202 Apr 29, 2024
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Apr 29, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-raw-pointers Area: raw pointers, MaybeUninit, NonNull C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants