Skip to content

Conversation

SimonSapin
Copy link
Contributor

This is similar to NonNull::cast.

Compared to the as operator (which has a wide range of meanings depending on the input and output types), a call to this method:

  • Can only go from a raw pointer to a raw pointer
  • Cannot change the pointer’s constness

… even when the pointed types are inferred based on context.

@rust-highfive
Copy link
Contributor

r? @Kimundi

(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 May 7, 2019
@SimonSapin
Copy link
Contributor Author

@rust-lang/libs how do you feel about adding this?

This is similar to `NonNull::cast`.

Compared to the `as` operator (which has a wide range of meanings
depending on the input and output types), a call to this method:

* Can only go from a raw pointer to a raw pointer
* Cannot change the pointer’s `const`ness

… even when the pointed types are inferred based on context.
@Centril
Copy link
Contributor

Centril commented May 7, 2019

I like the direction of this; it seems readable and particularly amenable for turbofish for added clarity. Moreover, it is constrained which seems like a plus in terms of local reasoning.

@sfackler
Copy link
Member

sfackler commented May 7, 2019

Seems plausible to me. We might similarly want methods to go *const T -> *mut T and vice versa.

@mark-i-m
Copy link
Contributor

mark-i-m commented May 7, 2019

Seems plausible to me. We might similarly want methods to go *const T -> *mut T and vice versa.

I would propose make_mut and make_const, but anyways I think that should be a different PR.

@SimonSapin
Copy link
Contributor Author

Or maybe only make_mut? Since *mut T coerces to *const T. And rather with a to_ or as_ prefix. (But yes, different PR.)

@alexcrichton
Copy link
Member

Agreed that it seems plausible to me (enough to land as unstable at least)

@Kimundi
Copy link
Contributor

Kimundi commented May 9, 2019

Seems useful!

@bors: r+

@bors
Copy link
Collaborator

bors commented May 9, 2019

📌 Commit d5e8190 has been approved by Kimundi

@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 9, 2019
Centril added a commit to Centril/rust that referenced this pull request May 9, 2019
Add a `cast` method to raw pointers.

This is similar to `NonNull::cast`.

Compared to the `as` operator (which has a wide range of meanings depending on the input and output types), a call to this method:

* Can only go from a raw pointer to a raw pointer
* Cannot change the pointer’s `const`ness

… even when the pointed types are inferred based on context.
bors added a commit that referenced this pull request May 9, 2019
Rollup of 5 pull requests

Successful merges:

 - #60601 (Add a `cast` method to raw pointers.)
 - #60638 (pin: make the to-module link more visible)
 - #60647 (cleanup: Remove `DefIndexAddressSpace`)
 - #60656 (Inline some Cursor calls for slices)
 - #60657 (Stabilize and re-export core::array in std)

Failed merges:

r? @ghost
@bors bors merged commit d5e8190 into rust-lang:master May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants