Skip to content

Commit 27acea0

Browse files
committed
Auto merge of #5193 - krishna-veerareddy:add-more-log-consts, r=flip1995
Add `LOG2_10` and `LOG10_2` to `approx_const` lint changelog: Add constants `LOG2_10` and `LOG10_2` to `approx_const` lint
2 parents bfa3343 + 533422f commit 27acea0

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

clippy_lints/src/approx_const.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ declare_clippy_lint! {
3737
}
3838

3939
// Tuples are of the form (constant, name, min_digits)
40-
const KNOWN_CONSTS: [(f64, &str, usize); 16] = [
40+
const KNOWN_CONSTS: [(f64, &str, usize); 18] = [
4141
(f64::E, "E", 4),
4242
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
4343
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
@@ -52,6 +52,8 @@ const KNOWN_CONSTS: [(f64, &str, usize); 16] = [
5252
(f64::LN_2, "LN_2", 5),
5353
(f64::LOG10_E, "LOG10_E", 5),
5454
(f64::LOG2_E, "LOG2_E", 5),
55+
(f64::LOG2_10, "LOG2_10", 5),
56+
(f64::LOG10_2, "LOG10_2", 5),
5557
(f64::PI, "PI", 3),
5658
(f64::SQRT_2, "SQRT_2", 5),
5759
];

tests/ui/approx_const.rs

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ fn main() {
4545
let my_log2_e = 1.4426950408889634;
4646
let no_log2_e = 1.442;
4747

48+
let log2_10 = 3.321928094887362;
49+
let no_log2_10 = 3.321;
50+
51+
let log10_2 = 0.301029995663981;
52+
let no_log10_2 = 0.301;
53+
4854
let my_pi = 3.1415;
4955
let almost_pi = 3.14;
5056
let no_pi = 3.15;

tests/ui/approx_const.stderr

+16-4
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,35 @@ error: approximate value of `f{32, 64}::consts::LOG2_E` found. Consider using it
9696
LL | let my_log2_e = 1.4426950408889634;
9797
| ^^^^^^^^^^^^^^^^^^
9898

99+
error: approximate value of `f{32, 64}::consts::LOG2_10` found. Consider using it directly
100+
--> $DIR/approx_const.rs:48:19
101+
|
102+
LL | let log2_10 = 3.321928094887362;
103+
| ^^^^^^^^^^^^^^^^^
104+
105+
error: approximate value of `f{32, 64}::consts::LOG10_2` found. Consider using it directly
106+
--> $DIR/approx_const.rs:51:19
107+
|
108+
LL | let log10_2 = 0.301029995663981;
109+
| ^^^^^^^^^^^^^^^^^
110+
99111
error: approximate value of `f{32, 64}::consts::PI` found. Consider using it directly
100-
--> $DIR/approx_const.rs:48:17
112+
--> $DIR/approx_const.rs:54:17
101113
|
102114
LL | let my_pi = 3.1415;
103115
| ^^^^^^
104116

105117
error: approximate value of `f{32, 64}::consts::PI` found. Consider using it directly
106-
--> $DIR/approx_const.rs:49:21
118+
--> $DIR/approx_const.rs:55:21
107119
|
108120
LL | let almost_pi = 3.14;
109121
| ^^^^
110122

111123
error: approximate value of `f{32, 64}::consts::SQRT_2` found. Consider using it directly
112-
--> $DIR/approx_const.rs:52:18
124+
--> $DIR/approx_const.rs:58:18
113125
|
114126
LL | let my_sq2 = 1.4142;
115127
| ^^^^^^
116128

117-
error: aborting due to 19 previous errors
129+
error: aborting due to 21 previous errors
118130

0 commit comments

Comments
 (0)