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

Implemented const casts of raw pointers #92657

Merged
merged 1 commit into from
Jan 9, 2022

Conversation

Kixunil
Copy link
Contributor

@Kixunil Kixunil commented Jan 7, 2022

This adds as_mut() method for *const T and as_const() for *mut T
which are intended to make casting of consts safer. This was discussed
in the internals discussion.

Given that this is a simple change and multiple people agreed to it including @RalfJung I decided to go ahead and open the PR.

@rust-highfive
Copy link
Collaborator

Updates src/tools/cargo.

cc @ehuss

Some changes occured to the Miri submodule

cc @rust-lang/miri

@rust-highfive
Copy link
Collaborator

r? @scottmcm

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

@rust-highfive
Copy link
Collaborator

⚠️ Warning ⚠️

  • These commits modify submodules.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 7, 2022
@Kixunil
Copy link
Contributor Author

Kixunil commented Jan 7, 2022

Sorry for the noise accidentally adding submodules, fixed it.

r? @RalfJung

I think you're the right person to review?

@rust-highfive rust-highfive assigned RalfJung and unassigned scottmcm Jan 7, 2022
@rust-log-analyzer

This comment has been minimized.

@inquisitivecrystal inquisitivecrystal added A-raw-pointers Area: raw pointers, MaybeUninit, NonNull T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jan 8, 2022
@SkiFire13
Copy link
Contributor

SkiFire13 commented Jan 8, 2022

It's a bit unfortunate that *mut T also has a as_mut method returning Option<&mut T>. How about cast_mut and cast_const?

@RalfJung
Copy link
Member

RalfJung commented Jan 8, 2022

Sorry for the noise accidentally adding submodules, fixed it.

r? @RalfJung

I think you're the right person to review?

Hm, no, not really... this is @rust-lang/libs-api territory.

@m-ou-se
Copy link
Member

m-ou-se commented Jan 8, 2022

This looks good to me. Can you open a tracking issue? Thanks!

@m-ou-se m-ou-se assigned m-ou-se and unassigned RalfJung Jan 8, 2022
@m-ou-se
Copy link
Member

m-ou-se commented Jan 8, 2022

It's a bit unfortunate that *mut T also has a as_mut method returning Option<&mut T>. How about cast_mut and cast_const?

Let's make sure we track this in the tracking issue and answer that question before stabilizing.

@Kixunil Kixunil mentioned this pull request Jan 8, 2022
3 tasks
This adds `as_mut()` method for `*const T` and `as_const()` for `*mut T`
which are intended to make casting of consts safer. This was discussed
in the [internals discussion][discussion].

[discussion]: https://internals.rust-lang.org/t/casting-constness-can-be-risky-heres-a-simple-fix/15933
@Kixunil
Copy link
Contributor Author

Kixunil commented Jan 8, 2022

Done. Was confused about that question at first so I reworded it to hopefully avoid confusion of others. Also filled the issue number in the PR.

@m-ou-se
Copy link
Member

m-ou-se commented Jan 8, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jan 8, 2022

📌 Commit 1a96623 has been approved by m-ou-se

@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 Jan 8, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 9, 2022
…askrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#92055 (Add release notes for 1.58)
 - rust-lang#92490 (Move crate drop-down to search results page)
 - rust-lang#92510 (Don't resolve blocks in foreign functions)
 - rust-lang#92573 (expand: Refactor InvocationCollector visitor for better code reuse)
 - rust-lang#92608 (rustdoc: Introduce a resolver cache for sharing data between early doc link resolution and later passes)
 - rust-lang#92657 (Implemented const casts of raw pointers)
 - rust-lang#92671 (Make `Atomic*::from_mut` return `&mut Atomic*`)
 - rust-lang#92673 (Remove useless collapse toggle on "all items" page)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 295ef3a into rust-lang:master Jan 9, 2022
@rustbot rustbot added this to the 1.60.0 milestone Jan 9, 2022
@Kixunil Kixunil deleted the ptr_as_const_mut branch January 9, 2022 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-raw-pointers Area: raw pointers, MaybeUninit, NonNull 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.

10 participants