about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-09-07 08:16:36 +0000
committerbors <bors@rust-lang.org>2021-09-07 08:16:36 +0000
commitb7c25e1679e8741ec52294765bb943c298ecefd7 (patch)
tree0f03ded31a3677e7bd3b00425a2006f28ff97885
parent17294b816156efa3a61f504823e75dfabd481357 (diff)
parenta7a5a5d9b00e6ecc0e518b1e806c1f3e2d216502 (diff)
downloadrust-b7c25e1679e8741ec52294765bb943c298ecefd7.tar.gz
rust-b7c25e1679e8741ec52294765bb943c298ecefd7.zip
Auto merge of #7642 - mikerite:fix-7641, r=flip1995
Add `TAU` to `approx_constant`

changelog: [`approx_constant`]: Add `TAU`
-rw-r--r--clippy_lints/src/approx_const.rs3
-rw-r--r--clippy_utils/src/msrvs.rs1
-rw-r--r--tests/ui/approx_const.rs4
-rw-r--r--tests/ui/approx_const.stderr18
4 files changed, 24 insertions, 2 deletions
diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs
index a57d8b67ed3..fb54ac1ec51 100644
--- a/clippy_lints/src/approx_const.rs
+++ b/clippy_lints/src/approx_const.rs
@@ -39,7 +39,7 @@ declare_clippy_lint! {
 }
 
 // Tuples are of the form (constant, name, min_digits, msrv)
-const KNOWN_CONSTS: [(f64, &str, usize, Option<RustcVersion>); 18] = [
+const KNOWN_CONSTS: [(f64, &str, usize, Option<RustcVersion>); 19] = [
     (f64::E, "E", 4, None),
     (f64::FRAC_1_PI, "FRAC_1_PI", 4, None),
     (f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5, None),
@@ -58,6 +58,7 @@ const KNOWN_CONSTS: [(f64, &str, usize, Option<RustcVersion>); 18] = [
     (f64::LOG10_E, "LOG10_E", 5, None),
     (f64::PI, "PI", 3, None),
     (f64::SQRT_2, "SQRT_2", 5, None),
+    (f64::TAU, "TAU", 3, Some(msrvs::TAU)),
 ];
 
 pub struct ApproxConstant {
diff --git a/clippy_utils/src/msrvs.rs b/clippy_utils/src/msrvs.rs
index 6fab17f07fe..fa57dfbb57e 100644
--- a/clippy_utils/src/msrvs.rs
+++ b/clippy_utils/src/msrvs.rs
@@ -15,6 +15,7 @@ msrv_aliases! {
     1,53,0 { OR_PATTERNS }
     1,52,0 { STR_SPLIT_ONCE }
     1,50,0 { BOOL_THEN }
+    1,47,0 { TAU }
     1,46,0 { CONST_IF_MATCH }
     1,45,0 { STR_STRIP_PREFIX }
     1,43,0 { LOG2_10, LOG10_2 }
diff --git a/tests/ui/approx_const.rs b/tests/ui/approx_const.rs
index fb57a0becbb..2ae4d613507 100644
--- a/tests/ui/approx_const.rs
+++ b/tests/ui/approx_const.rs
@@ -57,4 +57,8 @@ fn main() {
 
     let my_sq2 = 1.4142;
     let no_sq2 = 1.414;
+
+    let my_tau = 6.2832;
+    let almost_tau = 6.28;
+    let no_tau = 6.3;
 }
diff --git a/tests/ui/approx_const.stderr b/tests/ui/approx_const.stderr
index a49fd40bf33..4da1b8215ae 100644
--- a/tests/ui/approx_const.stderr
+++ b/tests/ui/approx_const.stderr
@@ -167,5 +167,21 @@ LL |     let my_sq2 = 1.4142;
    |
    = help: consider using the constant directly
 
-error: aborting due to 21 previous errors
+error: approximate value of `f{32, 64}::consts::TAU` found
+  --> $DIR/approx_const.rs:61:18
+   |
+LL |     let my_tau = 6.2832;
+   |                  ^^^^^^
+   |
+   = help: consider using the constant directly
+
+error: approximate value of `f{32, 64}::consts::TAU` found
+  --> $DIR/approx_const.rs:62:22
+   |
+LL |     let almost_tau = 6.28;
+   |                      ^^^^
+   |
+   = help: consider using the constant directly
+
+error: aborting due to 23 previous errors