From a7a5a5d9b00e6ecc0e518b1e806c1f3e2d216502 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Tue, 7 Sep 2021 05:50:04 +0200 Subject: [PATCH] Add `TAU` to `approx_constant` --- clippy_lints/src/approx_const.rs | 3 ++- clippy_utils/src/msrvs.rs | 1 + tests/ui/approx_const.rs | 4 ++++ tests/ui/approx_const.stderr | 18 +++++++++++++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index a57d8b67ed37..fb54ac1ec511 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); 18] = [ +const KNOWN_CONSTS: [(f64, &str, usize, Option); 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); 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 6fab17f07fe0..fa57dfbb57ed 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 fb57a0becbb2..2ae4d613507e 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 a49fd40bf337..4da1b8215ae0 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