Skip to content

Unclear explanation of fn_to_numeric_cast_with_truncation #2981

Closed
@dtolnay

Description

@dtolnay

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-documentationArea: Adding or improving documentationgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions