-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Minor clean up to a pile of unsafe code. #12445
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
another very nice clean up!!! 👍 |
I wonder if we could do something like: fn transmute_pod<T: Pod, U: Pod>(t: T) -> U { unsafe { cast::transmute(t) } } For things like |
@alexcrichton unfortunately |
@alexcrichton said he thought this was useless (and it's old logic: it's been there since before the runtime was written into Rust).
This trades an O(n) allocation + memcpy for a O(1) proc allocation (for the destructor). Most users only need &[u8] anyway (all of the users in the main repo), and so this offers large gains.
…referencing. These can all be written in a more controlled manner than with the transmute hammer, leading to (hopefully) safer code.
These calls are mutating their argument and so it's bad behaviour to be pretending that the values are immutable to rustc.
`as`-able transmutes, duplication and manual slice decomposition are silly.
(canceling the build, going to try to land the windows ignores first, sorry!) |
bors
added a commit
that referenced
this pull request
Feb 24, 2014
Commits for details. Highlights: - `flate` returns `CVec<u8>` to save reallocating a whole new `&[u8]` - a lot of `transmute`s removed outright or replaced with `as` (etc.)
matthiaskrgr
pushed a commit
to matthiaskrgr/rust
that referenced
this pull request
Mar 21, 2024
…dnet add documentation to the `span_lint_hir` functions As far as I could tell, these weren't documented anywhere, and since this is sometimes needed over `span_lint` for `#[allow]` attrs to work, I thought I would add a little bit of documentation. When I started with clippy development, I also had no idea what these functions were for. changelog: none
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.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Commits for details. Highlights:
flate
returnsCVec<u8>
to save reallocating a whole new&[u8]
transmute
s removed outright or replaced withas
(etc.)