rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.46k stars 1.55k forks source link

Decimal literal suffix of 0 (`2.` vs. `2.0`) #13022

Closed BD103 closed 4 months ago

BD103 commented 4 months ago

What it does

This lint checks if a floating-point number with no decimals explicitly writes .0 or just .

In the Bevy game engine there are a lot of examples that use floating-point numbers. Because so many people contribute to these examples, there's a large mix between literals like 1.0 and 1.. Here's the most egregious example. Having a lint that picks one form and denies the other would be great for consistency, though it should probably be within the pedantic or nursery groups.

I'm not sure how a user would choose which form they prefer, though, since exclusive lints are probably not a good idea.

Advantage

Drawbacks

Example

let x = 1.0;

Could be written as:

let x = 1.;

And vice-versa.

Alexendoo commented 4 months ago

Looks like there's a pending effort to get this into rustfmt - https://github.com/rust-lang/rustfmt/pull/5834

BD103 commented 4 months ago

Awesome, I didn't see that in my initial search. Thanks for pointing it out!