-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Implemented const casts of raw pointers #92657
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
Conversation
Updates src/tools/cargo. cc @ehuss Some changes occured to the Miri submodule cc @rust-lang/miri |
r? @scottmcm (rust-highfive has picked a reviewer for you, use r? to override) |
|
c110f3e
to
8b5c8fd
Compare
Sorry for the noise accidentally adding submodules, fixed it. r? @RalfJung I think you're the right person to review? |
This comment has been minimized.
This comment has been minimized.
8b5c8fd
to
a25df05
Compare
It's a bit unfortunate that |
Hm, no, not really... this is @rust-lang/libs-api territory. |
This looks good to me. Can you open a tracking issue? Thanks! |
Let's make sure we track this in the tracking issue and answer that question before stabilizing. |
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
a25df05
to
1a96623
Compare
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. |
@bors r+ |
📌 Commit 1a96623 has been approved by |
…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
I grepped the codebase for `as \*` and found a few places where we were doing explicit pointer casts but we could've been using std methods. The methods are safer because they don't allow changing mutability (unless we use cast_const or cast_mut, which don't allow changing the type). There are a few instances remaining where we cast to pointers to unsized types. These are actually fat raw pointers and they don't have std methods. Now they stand out because of the use of `as *`. This commit might require a bit of thought to review, and it turns out it has nothing to do with the MSRV bump (which gave us cast_const and cast_mut, but actually we don't use those, thankfully..). As a bit of trivia, though, the new cast_mut and cast_const methods were originally proposed and implemented by our own Kixunil: rust-lang/rust#92657
I grepped the codebase for `as \*` and found a few places where we were doing explicit pointer casts but we could've been using std methods. The methods are safer because they don't allow changing mutability (unless we use cast_const or cast_mut, which don't allow changing the type). There are a few instances remaining where we cast to pointers to unsized types. These are actually fat raw pointers and they don't have std methods. Now they stand out because of the use of `as *`. This commit might require a bit of thought to review, and it turns out it has nothing to do with the MSRV bump (which gave us cast_const and cast_mut, but actually we don't use those, thankfully..). As a bit of trivia, though, the new cast_mut and cast_const methods were originally proposed and implemented by our own Kixunil: rust-lang/rust#92657
This adds
as_mut()
method for*const T
andas_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.