The following code triggers excessive_precision:
fn main() {
let y = 10f32;
let x = y * 1_000_000_000.0;
println!("{}", x);
}
warning: float has excessive precision
--> src/main.rs:3:17
|
3 | let x = y * 1_000_000_000.0;
| ^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1000000000`
|
/cc @oli-obk @estk
@frol thanks for calling this one out.
This is actually an interesting case since the .0 is really acting as a stand in for f32 and of course it is technically "excessive precision". The .0 is common enough that i would be inclined to just ignore the error for this special case.
The other possibility is changing the help message to indicate that the programmer should use the postfix of f32 to indicate that the literal in question is in fact a float.
What do you think @oli-obk ?
Yea we should not lint this case
I can take this issue btw
Should the help message still be updated further for this issue? Got this lint when trying out clippy-preview today, and was confused as the help message proposes removing the . completely, but that just causes a compile error in my case and in the original example.
Additionally, I'm used to adding a single . (e.g. 1_000_000_000.) for float literals, which the lint still suggests to remove. I understand if a single . would be considered non-idiomatic, but I feel like the help should suggest changing it to .0.
Thanks for pointing this out! I opened a new issue for this.
Most helpful comment
Yea we should not lint this case