forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lint which checks that duration math isn't losing precision
**Description** Add a lint which checks for a binop or cast where the expression is converting a Duration to a floating point number, and losing precision along the way. The lint won't fire for most cases involving `as_nanos()` since converting that to floating point already gives the max precision. The lint is also restricted to an MSRV of 1.38.0, since that is when the `as_secs_{f32,f64}()` methods were stabilized. **Motivation** This change is motivated by [a rust stdlib ACP which proposed `as_millis_{f64,f32}`][ACP-link]. As part of that I did some code searches on github (see ACP for links) that showed a lot of code which converted Duration values to floating point using methods other than `as_secs_{f32,64}()`, and were losing precision because of that. This lint seems like a good way to raise awareness and prompt using the existing methods. [ACP-link]: rust-lang/libs-team#349 **Testing Done** Added UI tests, ran `cargo test`, followed the Clippy manual
- Loading branch information
Showing
9 changed files
with
570 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.