Skip to content
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

Merged
merged 2 commits into from
Jul 30, 2023
Merged

Conversation

lukas-code
Copy link
Member

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 a const 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

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 23, 2022
@rustbot
Copy link
Collaborator

rustbot commented Sep 23, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

r? @thomcc

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 23, 2022
@rustbot rustbot added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Sep 23, 2022
@thomcc
Copy link
Member

thomcc commented Sep 23, 2022

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

@rustbot rustbot removed the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 23, 2022
@rust-highfive rust-highfive assigned joshtriplett and unassigned thomcc Sep 23, 2022
@inquisitivecrystal inquisitivecrystal added relnotes Marks issues that should be documented in the release notes of the next release. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. labels Sep 24, 2022
@joshtriplett joshtriplett removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 3, 2022
@joshtriplett
Copy link
Member

@rfcbot merge

@rfcbot
Copy link

rfcbot commented Oct 3, 2022

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.

@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 Oct 3, 2022
@joshtriplett
Copy link
Member

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() }
Copy link
Member

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?

Copy link
Member Author

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)

@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 Oct 4, 2022
@rfcbot
Copy link

rfcbot commented Oct 4, 2022

🔔 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 Oct 14, 2022
@rfcbot
Copy link

rfcbot commented Oct 14, 2022

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.

@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Dec 8, 2022
@archshift
Copy link
Contributor

Any updates here?

@Amanieu
Copy link
Member

Amanieu commented May 22, 2023

@bors r+

@bors
Copy link
Contributor

bors commented May 22, 2023

📌 Commit e7047e6f79aaa492d2e13c553ca7a22fcdb682e7 has been approved by Amanieu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 22, 2023
@bors
Copy link
Contributor

bors commented May 22, 2023

🔒 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 self is your fork and upstream is this repository, you can resolve the conflict following these steps:

  1. git checkout nonnull_as_ref (switch to your branch)
  2. git fetch upstream master (retrieve the latest master)
  3. git rebase upstream/master -p (rebase on top of it)
  4. Follow the on-screen instruction to resolve conflicts (check git status if you got lost).
  5. git push self nonnull_as_ref --force-with-lease (update this PR)

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 git merge instead of git rebase which makes the PR commit history more difficult to read.

Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Cargo.lock conflict is handled during merge and rebase. This is normal, and you should still perform step 5 to update this PR.

Error message
CONFLICT (file location): src/test/ui/consts/const-eval/nonnull_as_ref_ub.stderr added in heads/homu-tmp inside a directory that was renamed in HEAD, suggesting it should perhaps be moved to tests/ui/const_prop/const-eval/nonnull_as_ref_ub.stderr.
CONFLICT (file location): src/test/ui/consts/const-eval/nonnull_as_ref_ub.rs added in heads/homu-tmp inside a directory that was renamed in HEAD, suggesting it should perhaps be moved to tests/ui/const_prop/const-eval/nonnull_as_ref_ub.rs.
CONFLICT (file location): src/test/ui/consts/const-eval/nonnull_as_ref.rs added in heads/homu-tmp inside a directory that was renamed in HEAD, suggesting it should perhaps be moved to tests/ui/const_prop/const-eval/nonnull_as_ref.rs.
Adding src/tools/rust-installer/test/image5/dir-to-install/foo
Adding src/tools/rust-installer/test/image4/dir-to-install/qux/bar
Adding src/tools/rust-installer/test/image4/baz
Adding src/tools/rust-installer/test/image3/bin/cargo
Adding src/tools/rust-installer/test/image2/something-to-install
Adding src/tools/rust-installer/test/image2/dir-to-install/bar
Adding src/tools/rust-installer/test/image2/bin/oldprogram
Adding src/tools/rust-installer/test/image1/something-to-not-install
Adding src/tools/rust-installer/test/image1/something-to-install
Adding src/tools/rust-installer/test/image1/dir-to-not-install/foo
Adding src/tools/rust-installer/test/image1/dir-to-install/foo
Adding src/tools/rust-installer/test/image1/bin/program2
Adding src/tools/rust-installer/test/image1/bin/program
Adding src/tools/rust-installer/test/image1/bin/bad-bin
Adding src/tools/rust-installer/test/image-docdir2/share/doc/cargo/cargodocs.txt
Adding src/tools/rust-installer/test/image-docdir2/share/doc/cargo/README
Adding src/tools/rust-installer/test/image-docdir1/share/doc/rust/rustdocs.txt
Adding src/tools/rust-installer/test/image-docdir1/share/doc/rust/README
Adding src/tools/rust-installer/test.sh
Adding src/tools/rust-installer/src/util.rs
Adding src/tools/rust-installer/src/tarballer.rs
Adding src/tools/rust-installer/src/scripter.rs
Adding src/tools/rust-installer/src/main.rs
Adding src/tools/rust-installer/src/lib.rs
Adding src/tools/rust-installer/src/generator.rs
Adding src/tools/rust-installer/src/compression.rs
Adding src/tools/rust-installer/src/combiner.rs
Adding src/tools/rust-installer/rust-installer-version
Adding src/tools/rust-installer/make-tarballs.sh
Adding src/tools/rust-installer/install-template.sh
Adding src/tools/rust-installer/gen-installer.sh
Adding src/tools/rust-installer/gen-install-script.sh
Adding src/tools/rust-installer/combine-installers.sh
Adding src/tools/rust-installer/README.md
Adding src/tools/rust-installer/Cargo.toml
Adding src/tools/rust-installer/.gitignore
Auto-merging library/core/src/ptr/non_null.rs
warning: inexact rename detection was skipped due to too many files.
warning: you may want to set your merge.renamelimit variable to at least 27325 and retry the command.
Automatic merge failed; fix conflicts and then commit the result.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 22, 2023
@workingjubilee
Copy link
Member

@bors r=Amanieu

@bors
Copy link
Contributor

bors commented Jul 30, 2023

📌 Commit 855b8b8 has been approved by Amanieu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 30, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jul 30, 2023
`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
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 30, 2023
…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
@bors bors merged commit e3ca397 into rust-lang:master Jul 30, 2023
@rustbot rustbot added this to the 1.73.0 milestone Jul 30, 2023
@lukas-code lukas-code deleted the nonnull_as_ref branch July 30, 2023 21:50
@dtolnay dtolnay mentioned this pull request Sep 9, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.