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

Minor clean up to a pile of unsafe code. #12445

Closed
wants to merge 5 commits into from

Conversation

huonw
Copy link
Member

@huonw huonw commented Feb 21, 2014

Commits for details. Highlights:

  • flate returns CVec<u8> to save reallocating a whole new &[u8]
  • a lot of transmutes removed outright or replaced with as (etc.)

@flaper87
Copy link
Contributor

another very nice clean up!!! 👍

@alexcrichton
Copy link
Member

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 f32 -> u32 and such.

@huonw
Copy link
Member Author

huonw commented Feb 22, 2014

@alexcrichton unfortunately &T is Pod so that wouldn't be safe.

@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.
@alexcrichton
Copy link
Member

(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.)
@bors bors closed this Feb 24, 2014
@huonw huonw deleted the less-unsafe branch February 24, 2014 23:56
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants