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

Unclear explanation of fn_to_numeric_cast_with_truncation #2981

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

Unclear explanation of fn_to_numeric_cast_with_truncation #2981

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_with_truncation

What it does

Checks for casts of a function pointer to a numeric type not enough to store address.

Why is this bad

Casting a function pointer to not eligable type could truncate the address value.

"Eligable" looks like it was intended to be "eligible", but I find "eligible type" vs "not eligible type" not a clear way to identify types that are wide enough to hold the address vs not wide enough.

I think this lint would be sufficiently justified by saying:

- Checks for casts of a function pointer to a numeric type not enough to store address.
+ Checks for casts of a function pointer to a numeric type not wide enough to store address.
- Casting a function pointer to not eligable type could truncate the address value.
+ Such a cast discards some bits of the function's address. If this is intended, it would
+ be more clearly expressed by casting to usize first, then casting the usize to the
+ intended type (with a comment) to perform the truncation.

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

phansch commented Oct 6, 2018

This was fixed as part of #3251 (fn_to_numeric_cast and fn_to_numeric_cast_with_truncation)

@phansch phansch closed this as completed Oct 6, 2018
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

3 participants