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

Tracking Issue for ptr_const_cast #92675

Closed
1 of 3 tasks
Kixunil opened this issue Jan 8, 2022 · 8 comments · Fixed by #100184
Closed
1 of 3 tasks

Tracking Issue for ptr_const_cast #92675

Kixunil opened this issue Jan 8, 2022 · 8 comments · Fixed by #100184
Labels
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

@Kixunil
Copy link
Contributor

Kixunil commented Jan 8, 2022

Feature gate: #![feature(ptr_const_cast)]

This is a tracking issue for methods on pointers for casting constness without changing the type

Public API

impl<T: ?Sized> *const T {
    pub fn as_mut(self) -> *mut T;
}

impl<T: ?Sized> *mut T {
    pub fn as_const(self) -> *const T;
}

Steps / History

Unresolved Questions

  • *mut T also already has as_mut() which does something different and has a different signature, adding a mehod of the same name to *const T could be confusing, so maybe a better name should be used. cast_const/cast_mut was suggested. Resolved to use cast_*
@Kixunil Kixunil added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jan 8, 2022
@josephlr
Copy link
Contributor

I like this function (as it allows a codebase to avoid uses of as if they desire). I agree thta as_mut() could lead to some ambiguity, and cast_mut seems better to me. It's the most similar to cast, so having a similar name seems correct.

As noted in the documentation, a cast_const method isn't strictly necessary, but could be nice for symmetry's sake.

@Kixunil
Copy link
Contributor Author

Kixunil commented Apr 20, 2022

I'm starting to like cast_ naming as it seems to be a bit more readable too. Will try to find the time for a PR. I don't mind anyone else doing it either. It's a trivial change anyway.

@cuviper
Copy link
Member

cuviper commented Jun 16, 2022

Once they're called cast_, I wonder if we should also add a type parameter like the existing cast method, so you don't have to double up .cast().cast_const() etc.

(However, they currently document that as an explicit feature, not changing the type.)

@Kixunil
Copy link
Contributor Author

Kixunil commented Jun 17, 2022

@cuviper yes, not changing the type is the main point because it protects against refactors. You can already do both with as.

More detailed explanation

@joshtriplett
Copy link
Member

Shall we rename these to cast_*, and also stabilize them?

@rfcbot merge

@rfcbot
Copy link

rfcbot commented Jul 20, 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 Jul 20, 2022
Kixunil added a commit to Kixunil/rust that referenced this issue Jul 21, 2022
This renames the methods to use the `cast_` prefix instead of `as_` to
make it more readable and avoid confusion with `<*mut T>::as_mut()`
which is `unsafe` and returns a reference.

See rust-lang#92675
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 22, 2022
…cast, r=scottmcm

Rename `<*{mut,const} T>::as_{const,mut}` to `cast_`

This renames the methods to use the `cast_` prefix instead of `as_` to
make it more readable and avoid confusion with `<*mut T>::as_mut()`
which is `unsafe` and returns a reference.

Sorry, didn't notice ACP process exists, opened rust-lang/libs-team#51

See rust-lang#92675
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 22, 2022
…cast, r=scottmcm

Rename `<*{mut,const} T>::as_{const,mut}` to `cast_`

This renames the methods to use the `cast_` prefix instead of `as_` to
make it more readable and avoid confusion with `<*mut T>::as_mut()`
which is `unsafe` and returns a reference.

Sorry, didn't notice ACP process exists, opened rust-lang/libs-team#51

See rust-lang#92675
@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 Jul 26, 2022
@rfcbot
Copy link

rfcbot commented Jul 26, 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 Aug 5, 2022
@rfcbot
Copy link

rfcbot commented Aug 5, 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.

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Aug 11, 2022
…r=m-ou-se

Stabilize ptr_const_cast

This stabilizes `ptr_const_cast` feature as was decided in a recent
[FCP](rust-lang#92675 (comment))

Closes rust-lang#92675
@bors bors closed this as completed in 2a3ce78 Aug 11, 2022
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Sep 8, 2022
workingjubilee pushed a commit to tcdi/postgrestd that referenced this issue Sep 15, 2022
This stabilizes `ptr_const_cast` feature as was decided in a recent
[FCP](rust-lang/rust#92675 (comment))

Closes #92675
workingjubilee pushed a commit to tcdi/postgrestd that referenced this issue Sep 15, 2022
Stabilize ptr_const_cast

This stabilizes `ptr_const_cast` feature as was decided in a recent
[FCP](rust-lang/rust#92675 (comment))

Closes #92675
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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