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

Replace misaligned_transmute lint #2661

Merged
merged 2 commits into from
Apr 11, 2018

Conversation

devonhollowood
Copy link
Contributor

In light of the discussion at #2418 and #2400, this deprecates misaligned_transmute and replaces it with two new lints: cast_ptr_alignment and transmute_ptr_to_ptr.

This is done by adding two new lints: cast_ptr_alignment and
transmute_ptr_to_ptr. These will replace misaligned_transmute.
@devonhollowood devonhollowood changed the title Ptr ptr casts Replace misaligned_transmute lint Apr 11, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Apr 11, 2018

Great work! Thanks!

@oli-obk oli-obk merged commit 8ec61a6 into rust-lang:master Apr 11, 2018
@Amanieu
Copy link
Member

Amanieu commented Apr 17, 2018

Could we make this lint not deny by default? It triggers on code which casts *mut u8 to *mut T which is a common pattern. It is perfectly safe since *mut u8 is only used for type erasure and we "know" that the pointer was originally a *mut T and is therefore correctly aligned.

@oli-obk
Copy link
Contributor

oli-obk commented Apr 17, 2018

@Amanieu can you give links to some examples? I don't think it's too common.

I think we should keep this lint as deny by default and you should allow it for your special case, because you know you checked this. Making it warn by default wouldn't change the annoyingness you get from it.

We can't know your *mut u8 came from a *mut T originally, so we are overly conservative. This is true for many of our lints, and disabling them explicitly at the use site shows future readers that you have actually considered all the implications locally and are considering it safe

@Amanieu
Copy link
Member

Amanieu commented Apr 17, 2018

The specific case that I am hitting is in this macro.

But I guess I can work around it by adding #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] in the macro...

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.

3 participants