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

Justification needed for fn_to_numeric_cast #2980

Closed
dtolnay opened this issue Jul 31, 2018 · 1 comment
Closed

Justification needed for fn_to_numeric_cast #2980

dtolnay opened this issue Jul 31, 2018 · 1 comment
Labels
A-documentation Area: Adding or improving documentation good-first-issue These issues are a good way to get started with Clippy

Comments

@dtolnay
Copy link
Member

dtolnay commented Jul 31, 2018

https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#fn_to_numeric_cast

What it does

Checks for casts of a function pointer to a numeric type except usize.

Why is this bad

Casting a function pointer to something other than usize is not a good style.

Justifying a style lint by calling it not good style is not a justification. I know "style" lints can be more difficult to justify than lints that catch what are almost certain to be bugs, but I looked through the "Why is this bad" section of all 81 other style lints present in Clippy 0.0.212 and I believe every other style lint is adequately justified.

I don't disagree with this lint, but by itself this explanation is not something I can point someone to and have them understand why I am asking them to change their code.

Mentioning @VKlayd who worked on this lint in #2814.

@oli-obk oli-obk added good-first-issue These issues are a good way to get started with Clippy A-documentation Area: Adding or improving documentation labels Aug 1, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Aug 1, 2018

A few points that should be in the "why is this bad" section:

  • anything other than usize/isize is not portable across architectures, because you end up losing bits if the target type is too small or end up with a bunch of extra bits that waste space and add more instructions to the final binary than strictly necessary for the problem
  • isize is signed, which makes little sense for an address, so usize is preferrable
  • pointer sized integers (isize/usize) are the correct type for holding a pointer without any extra type information holding you back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documentation Area: Adding or improving documentation good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

No branches or pull requests

2 participants