Skip to content

add a lint for useless transmutes #11400

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

Closed
emberian opened this issue Jan 8, 2014 · 7 comments
Closed

add a lint for useless transmutes #11400

emberian opened this issue Jan 8, 2014 · 7 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@emberian
Copy link
Member

emberian commented Jan 8, 2014

fn main() {
    unsafe { std::cast::transmute::<int, int> ( 52 ) };
}

Should have a warning. In general, transmute::<T, T> should be warned against.

@sanxiyn
Copy link
Member

sanxiyn commented Jan 8, 2014

I am not sure about this. In transmute::<T, U>, T can be a platform-specific type, which may or may not be equal to U depending on the platform. It would be annoying to get warned in such cases.

@fhahn
Copy link
Contributor

fhahn commented Jan 13, 2014

I think there was a similar problem with #11135 (a lint for unnecessary type casts). This lint defaults to allow at the moment, partly because of the problem with platfrom specific types. There are some thoughts on this problem in the comments.

@pongad
Copy link
Contributor

pongad commented Jan 31, 2014

Would it be feasible to write up a list of platform-specific types? Ideally, users won't be creating new ones, so we can exclude them from the warning.

@fhahn
Copy link
Contributor

fhahn commented Feb 5, 2014

I think this could work. Some lints already use static lists, the attr_usage lint uses a a list of attribute names to check if attributes are known to the compiler. I could write a proof of concept patch if this approach seems feasible.

@tshepang
Copy link
Member

tshepang commented Jan 4, 2015

That sample code should now be:

fn main() {
    unsafe { std::mem::transmute::<int, int> ( 52 ) };
}

@steveklabnik
Copy link
Member

/cc @Manishearth , does clippy have one of these?

@Manishearth
Copy link
Member

@Manishearth Manishearth removed the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Nov 7, 2015
@arielb1 arielb1 closed this as completed Nov 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

8 participants