Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upLinux: Clean up raw pointer casts #71
Merged
+5
−5
Conversation
The intermediate cast to `*mut _` is completely useless here: the input is already a `*mut`.
The idea here presumably was for the first cast just to turn the `*mut` into a `*const`, without changing the targe type; however, the input actually was not `u8` to begin with -- so this was actually casting to a completely bogus interediate type...
For casts that only change a reference into a raw pointer, or change between `*const` and `*mut`, always use `_` instead of a full type, to make it clear that the target type doesn't change.
While it might have been necessary at some point in the cast between `*mut` and `*const` in a separate step from casting between different target types, it is definitely not needed with current Rust. One might argue that doing it in a separate step makes the change more explicit. However, in some cases it's obvious anyway (when the source is `.as_ptr()` or `.as_mut_prt()`) -- and even where it's not quite as obvious, it's not clear at all that the unnecessary extra step isn't actually adding more confusion...
mbrubeck
commented
May 13, 2016
|
@bors-servo r+ |
|
|
bors-servo
added a commit
that referenced
this pull request
May 13, 2016
Linux: Clean up raw pointer casts Various cleanups to make raw pointer casts simpler and more consistent.
|
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
antrik commentedMay 13, 2016
Various cleanups to make raw pointer casts simpler and more consistent.