-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking Issue for const_ptr_as_ref
#91822
Comments
Make `PTR::as_ref` and similar methods `const`. Tracking issue: rust-lang#91822 Feature gate: `#![feature(const_ptr_as_ref)]` ```rust // core::ptr impl<T: ?Sized> *const T { pub const unsafe fn as_ref<'a>(self) -> Option<&'a T>; pub const unsafe fn as_uninit_ref<'a>(self) -> Option<&'a MaybeUninit<T>> where T: Sized; pub const unsafe fn as_uninit_slice<'a>(self) -> Option<&'a [MaybeUninit<T>]>; } impl<T: ?Sized> *mut T { pub const unsafe fn as_ref<'a>(self) -> Option<&'a T>; pub const unsafe fn as_uninit_ref<'a>(self) -> Option<&'a MaybeUninit<T>> where T: Sized; pub const unsafe fn as_mut<'a>(self) -> Option<&'a mut T>; pub const unsafe fn as_uninit_mut<'a>(self) -> Option<&'a mut MaybeUninit<T>> where T: Sized; pub const unsafe fn as_uninit_slice<'a>(self) -> Option<&'a [MaybeUninit<T>]>; pub const unsafe fn as_uninit_slice_mut<'a>(self) -> Option<&'a mut [MaybeUninit<T>]>; } impl<T: Sized> NonNull<T> { pub const unsafe fn as_uninit_ref<'a>(&self) -> &'a MaybeUninit<T>; pub const unsafe fn as_uninit_mut<'a>(&mut self) -> &'a mut MaybeUninit<T>; } impl<T: ?Sized> NonNull<T> { pub const unsafe fn as_ref<'a>(&self) -> &'a T; pub const unsafe fn as_mut<'a>(&mut self) -> &'a mut T; pub const unsafe fn as_uninit_slice<'a>(&self) -> &'a [MaybeUninit<T>]; pub const unsafe fn as_uninit_slice_mut<'a>(&self) -> &'a mut [MaybeUninit<T>]; } ```
`const`-stablilize `NonNull::as_ref` A bunch of pointer to reference methods have been made unstably const some time ago in rust-lang#91823 under the feature gate `const_ptr_as_ref`. Out of these, `NonNull::as_ref` can be implemented as a `const fn` in stable rust today, so i hereby propose to const stabilize this function only. Tracking issue: rust-lang#91822 `@rustbot` label +T-libs-api -T-libs
`const`-stablilize `NonNull::as_ref` A bunch of pointer to reference methods have been made unstably const some time ago in rust-lang#91823 under the feature gate `const_ptr_as_ref`. Out of these, `NonNull::as_ref` can be implemented as a `const fn` in stable rust today, so i hereby propose to const stabilize this function only. Tracking issue: rust-lang#91822 ``@rustbot`` label +T-libs-api -T-libs
… r=workingjubilee Implement ptr_as_ref_unchecked Implementation of rust-lang#122034. Prefixed the feature name with `ptr_` for clarity. Linked const-unstability to rust-lang#91822, so the post there should probably be updated to mentions the 3 new methods when/if this PR is merged.
… r=workingjubilee Implement ptr_as_ref_unchecked Implementation of rust-lang#122034. Prefixed the feature name with `ptr_` for clarity. Linked const-unstability to rust-lang#91822, so the post there should probably be updated to mentions the 3 new methods when/if this PR is merged.
… r=workingjubilee Implement ptr_as_ref_unchecked Implementation of rust-lang#122034. Prefixed the feature name with `ptr_` for clarity. Linked const-unstability to rust-lang#91822, so the post there should probably be updated to mentions the 3 new methods when/if this PR is merged.
Rollup merge of rust-lang#122492 - GrigorenkoPV:ptr_as_ref_unchecked, r=workingjubilee Implement ptr_as_ref_unchecked Implementation of rust-lang#122034. Prefixed the feature name with `ptr_` for clarity. Linked const-unstability to rust-lang#91822, so the post there should probably be updated to mentions the 3 new methods when/if this PR is merged.
Hello! Now that #122492 has been merged, 3 new methods are also const-gated behind this flag
Should they be added to the OP? |
I have added them to the list. |
@rust-lang/libs-api I propose we const-stabilize the subset of the methods above that are stable for non-const calls: // core::ptr
impl<T: ?Sized> *const T {
pub const unsafe fn as_ref<'a>(self) -> Option<&'a T>;
}
impl<T: ?Sized> *mut T {
pub const unsafe fn as_ref<'a>(self) -> Option<&'a T>;
pub const unsafe fn as_mut<'a>(self) -> Option<&'a mut T>;
}
impl<T: ?Sized> NonNull<T> {
pub const unsafe fn as_mut<'a>(&mut self) -> &'a mut T;
} The rest should be moved to the feature gate tracking their general stability, no separate const-feature-gate is needed. (EDIT: that is happening in #130164) |
Ah wait, the So then only one function is left to be stabilized here: |
@rfcbot fcp merge Subsequent to #129195, we are ready to stabilize rust/library/core/src/ptr/non_null.rs Lines 400 to 404 in d7522d8
This function is the rust/library/core/src/ptr/non_null.rs Lines 362 to 367 in d7522d8
|
Team member @dtolnay 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. |
move some const fn out of the const_ptr_as_ref feature When a `const fn` is still `#[unstable]`, it should generally use the same feature to track its regular stability and const-stability. Then when that feature moves towards stabilization we can decide whether the const-ness can be stabilized as well, or whether it should be moved into a new feature. Also, functions like `ptr::as_ref` (which returns an `Option<&mut T>`) require `is_null`, which is tricky and blocked on some design concerns (see rust-lang#74939). So move those to the is_null feature gate, as they should be stabilized together with `ptr.is_null()`. Affects rust-lang#91822, rust-lang#122034, rust-lang#75402, rust-lang#74939
move some const fn out of the const_ptr_as_ref feature When a `const fn` is still `#[unstable]`, it should generally use the same feature to track its regular stability and const-stability. Then when that feature moves towards stabilization we can decide whether the const-ness can be stabilized as well, or whether it should be moved into a new feature. Also, functions like `ptr::as_ref` (which returns an `Option<&mut T>`) require `is_null`, which is tricky and blocked on some design concerns (see rust-lang#74939). So move those to the is_null feature gate, as they should be stabilized together with `ptr.is_null()`. Affects rust-lang#91822, rust-lang#122034, rust-lang#75402, rust-lang#74939
Rollup merge of rust-lang#130164 - RalfJung:const_ptr_as_ref, r=dtolnay move some const fn out of the const_ptr_as_ref feature When a `const fn` is still `#[unstable]`, it should generally use the same feature to track its regular stability and const-stability. Then when that feature moves towards stabilization we can decide whether the const-ness can be stabilized as well, or whether it should be moved into a new feature. Also, functions like `ptr::as_ref` (which returns an `Option<&mut T>`) require `is_null`, which is tricky and blocked on some design concerns (see rust-lang#74939). So move those to the is_null feature gate, as they should be stabilized together with `ptr.is_null()`. Affects rust-lang#91822, rust-lang#122034, rust-lang#75402, rust-lang#74939
🔔 This is now entering its final comment period, as per the review above. 🔔 |
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. |
…-referees, r=tgross35 Stabilize 5 `const_mut_refs`-dependent API Since `const_mut_refs` and `const_refs_to_cell` have been stabilized, we now may create mutable references inside our library API. Thus we now stabilize the `const fn` version of these public library APIs which required such in their implementation: - const `NonNull::as_mut` rust-lang#91822 (comment) - const `slice::{first,last}_mut`: rust-lang#83570 (comment) - const `str::as_{mut_ptr,bytes_mut}`: rust-lang#130086 (comment) - const `str::from_utf8_unchecked_mut`: rust-lang#91005 (comment) - const `UnsafeCell::get_mut`: rust-lang#88836 (comment)
…-referees, r=tgross35 Stabilize 5 `const_mut_refs`-dependent API Since `const_mut_refs` and `const_refs_to_cell` have been stabilized, we now may create mutable references inside our library API. Thus we now stabilize the `const fn` version of these public library APIs which required such in their implementation: - const `NonNull::as_mut` rust-lang#91822 (comment) - const `slice::{first,last}_mut`: rust-lang#83570 (comment) - const `str::as_{mut_ptr,bytes_mut}`: rust-lang#130086 (comment) - const `str::from_utf8_unchecked_mut`: rust-lang#91005 (comment) - const `UnsafeCell::get_mut`: rust-lang#88836 (comment)
…-referees, r=tgross35 Stabilize 5 `const_mut_refs`-dependent API Since `const_mut_refs` and `const_refs_to_cell` have been stabilized, we now may create mutable references inside our library API. Thus we now stabilize the `const fn` version of these public library APIs which required such in their implementation: - const `NonNull::as_mut` rust-lang#91822 (comment) - const `slice::{first,last}_mut`: rust-lang#83570 (comment) - const `str::as_{mut_ptr,bytes_mut}`: rust-lang#130086 (comment) - const `str::from_utf8_unchecked_mut`: rust-lang#91005 (comment) - const `UnsafeCell::get_mut`: rust-lang#88836 (comment)
Rollup merge of rust-lang#131177 - workingjubilee:stabilize-const-mut-referees, r=tgross35 Stabilize 5 `const_mut_refs`-dependent API Since `const_mut_refs` and `const_refs_to_cell` have been stabilized, we now may create mutable references inside our library API. Thus we now stabilize the `const fn` version of these public library APIs which required such in their implementation: - const `NonNull::as_mut` rust-lang#91822 (comment) - const `slice::{first,last}_mut`: rust-lang#83570 (comment) - const `str::as_{mut_ptr,bytes_mut}`: rust-lang#130086 (comment) - const `str::from_utf8_unchecked_mut`: rust-lang#91005 (comment) - const `UnsafeCell::get_mut`: rust-lang#88836 (comment)
Feature gate:
#![feature(const_ptr_as_ref)]
Public API
Steps / History
PTR::as_ref
and similar methodsconst
. #91823Unresolved Questions
The text was updated successfully, but these errors were encountered: