-
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
const
-stablilize NonNull::as_ref
#102198
const
-stablilize NonNull::as_ref
#102198
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @thomcc (rust-highfive has picked a reviewer for you, use r? to override) |
This seems fine to me but needs FCP, so I'll assign to someone on t-libs-api. r? @joshtriplett @rustbot label +T-libs-api -T-libs |
@rfcbot merge |
Team member @joshtriplett 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. |
cc @rust-lang/wg-const-eval; does this look reasonable to you? |
#[must_use] | ||
#[inline] | ||
pub const unsafe fn as_ref<'a>(&self) -> &'a T { | ||
// SAFETY: the caller must guarantee that `self` meets all the | ||
// requirements for a reference. | ||
unsafe { &*self.as_ptr() } | ||
unsafe { &*self.as_ptr().cast_const() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the cast_const
needed now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the cast it will fail to compile with error[E0658]: dereferencing raw mutable pointers in constant functions is unstable
(playground)
7fae23e
to
e7047e6
Compare
🔔 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. |
Any updates here? |
@bors r+ |
📌 Commit e7047e6f79aaa492d2e13c553ca7a22fcdb682e7 has been approved by It is now in the queue for this repository. |
🔒 Merge conflict This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again. How do I rebase?Assuming
You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial. Please avoid the "Resolve conflicts" button on GitHub. It uses Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Error message
|
e7047e6
to
855b8b8
Compare
@bors r=Amanieu |
`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
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#98154 (merge functionality of `io::Sink` into `io::Empty`) - rust-lang#102198 (`const`-stablilize `NonNull::as_ref`) - rust-lang#114074 (inline format!() args from rustc_middle up to and including rustc_codegen_llvm (3)) - rust-lang#114246 (Weaken unnameable_types lint) - rust-lang#114256 (Fix invalid suggestion for mismatched types in closure arguments) - rust-lang#114258 (Simplify `Span::can_be_used_for_suggestions` a little tiny bit) r? `@ghost` `@rustbot` modify labels: rollup
A bunch of pointer to reference methods have been made unstably const some time ago in #91823 under the feature gate
const_ptr_as_ref
.Out of these,
NonNull::as_ref
can be implemented as aconst fn
in stable rust today, so i hereby propose to const stabilize this function only.Tracking issue: #91822
@rustbot label +T-libs-api -T-libs