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

"casting u32 to f64 may become silently lossy if types change" doesn't make sense #3964

Closed
hrydgard opened this issue Apr 15, 2019 · 2 comments · Fixed by #4021
Closed

"casting u32 to f64 may become silently lossy if types change" doesn't make sense #3964

hrydgard opened this issue Apr 15, 2019 · 2 comments · Fixed by #4021
Labels
A-documentation Area: Adding or improving documentation good-first-issue These issues are a good way to get started with Clippy

Comments

@hrydgard
Copy link

I'm pretty sure this warning should be removed. Same with f32 to f64, s32 to f64 and so on. All integer types with sizes <= u32 are trivially covered by f64, due to the 53 bit mantissa, and f32 should be too, right?

To me, having to do f64::from() is a lot visually noisier than "as f64" and I see no benefit in warning for something that will never occur in practice. I don't see any scenario in which the definition of f64 would change...

@oli-obk
Copy link
Contributor

oli-obk commented Apr 15, 2019

It's not that the definition of f64 will change. It's also not the fact that converting an u32 to a f64 is ever lossy. It's about the fact that your source type might change (e.g. if you change the argument type from u32 to u64 in the following function)

fn foo(u: u32) {
    // loads of code here
    let x = u as f64;
    // use x
}

The conversion of u32 to f64 is not lossy here, but if the type of u is changed later, then you can get a lossy cast without realizing it, because everything still compiles.

@hrydgard
Copy link
Author

hrydgard commented Apr 15, 2019

I see. Then I guess my issue is that the wording of the warning is unclear. "If types will change" suggests the agency of the compiler, "if you later change the type" or something like that would be better I think.

@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 Apr 15, 2019
kraai added a commit to kraai/rust-clippy that referenced this issue Apr 24, 2019
bors added a commit that referenced this issue Apr 24, 2019
Change "if types change" to "if you later change the type"

Fixes #3964.

changelog: change wording of `cast_lossless` message
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

Successfully merging a pull request may close this issue.

2 participants