-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lint to detect conversions between degrees and radians
- Loading branch information
1 parent
e022819
commit 85670af
Showing
5 changed files
with
119 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#![warn(clippy::floating_point_improvements)] | ||
|
||
fn main() { | ||
let x = 2f32; | ||
let _ = x * (std::f32::consts::PI / 180.0); | ||
let _ = (std::f32::consts::PI / 180.0) * x; | ||
let _ = -x * (std::f32::consts::PI / 180.0); | ||
let _ = x * (180.0 / std::f32::consts::PI); | ||
let _ = (180.0 / std::f32::consts::PI) * x; | ||
|
||
let x = 2f64; | ||
let _ = x * (std::f64::consts::PI / 180.0); | ||
let _ = (std::f64::consts::PI / 180.0) * x; | ||
let _ = x * (180.0 / std::f64::consts::PI); | ||
let _ = (180.0 / std::f64::consts::PI) * x; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
error: conversions between degrees and radians can be expressed more succinctly | ||
--> $DIR/floating_point_deg_rad_conversion.rs:5:13 | ||
| | ||
LL | let _ = x * (std::f32::consts::PI / 180.0); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_radians()` | ||
| | ||
= note: `-D clippy::floating-point-improvements` implied by `-D warnings` | ||
|
||
error: conversions between degrees and radians can be expressed more succinctly | ||
--> $DIR/floating_point_deg_rad_conversion.rs:6:13 | ||
| | ||
LL | let _ = (std::f32::consts::PI / 180.0) * x; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_radians()` | ||
|
||
error: conversions between degrees and radians can be expressed more succinctly | ||
--> $DIR/floating_point_deg_rad_conversion.rs:7:13 | ||
| | ||
LL | let _ = -x * (std::f32::consts::PI / 180.0); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-x).to_radians()` | ||
|
||
error: conversions between degrees and radians can be expressed more succinctly | ||
--> $DIR/floating_point_deg_rad_conversion.rs:8:13 | ||
| | ||
LL | let _ = x * (180.0 / std::f32::consts::PI); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_degrees()` | ||
|
||
error: conversions between degrees and radians can be expressed more succinctly | ||
--> $DIR/floating_point_deg_rad_conversion.rs:9:13 | ||
| | ||
LL | let _ = (180.0 / std::f32::consts::PI) * x; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_degrees()` | ||
|
||
error: conversions between degrees and radians can be expressed more succinctly | ||
--> $DIR/floating_point_deg_rad_conversion.rs:12:13 | ||
| | ||
LL | let _ = x * (std::f64::consts::PI / 180.0); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_radians()` | ||
|
||
error: conversions between degrees and radians can be expressed more succinctly | ||
--> $DIR/floating_point_deg_rad_conversion.rs:13:13 | ||
| | ||
LL | let _ = (std::f64::consts::PI / 180.0) * x; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_radians()` | ||
|
||
error: conversions between degrees and radians can be expressed more succinctly | ||
--> $DIR/floating_point_deg_rad_conversion.rs:14:13 | ||
| | ||
LL | let _ = x * (180.0 / std::f64::consts::PI); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_degrees()` | ||
|
||
error: conversions between degrees and radians can be expressed more succinctly | ||
--> $DIR/floating_point_deg_rad_conversion.rs:15:13 | ||
| | ||
LL | let _ = (180.0 / std::f64::consts::PI) * x; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_degrees()` | ||
|
||
error: aborting due to 9 previous errors | ||
|