-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 raw-pointer-to-reference conversion methods #122034
Comments
… 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.
/bikeshed
I personally think this is fine. Follows the conventions, and most of the cases where I've reached for these methods, they've been inside macros etc. where it matters way less. I know it's not really an option now (maybe it is?) but personally would have preferred |
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
Feature gate:
#![feature(as_ref_unchecked)]
(or similar)This is a tracking issue for raw-pointer-to-reference conversion methods (rust-lang/libs-team#342).
With #106116, we have methods for almost all casts/conversions one wants to do on references and pointers, to avoid
as
casts and prefix operators. Just one direction is missing: turning raw pointers into references. Here we haveas_ref
/as_mut
, but they behave different from&*ptr
/&mut *ptr
: they return anOption
and perform a null-check. (These are the only methods on raw pointers that perform a null check.)Public API
Motivating examples or use cases
Some random examples from a quick grep of the rustc sources:
The examples above then become
Unfortunately, since the
as_mut
name is already taken, these are all longer than the prefix variants. But they can be read left-to-right which is an advantage.Steps / History
Unresolved Questions
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: