Skip to content

Commit 9f8fb80

Browse files
committed
Add run-rustfix to excessive_precision test
1 parent 29211be commit 9f8fb80

File tree

3 files changed

+83
-19
lines changed

3 files changed

+83
-19
lines changed

tests/ui/excessive_precision.fixed

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// run-rustfix
2+
#![warn(clippy::excessive_precision)]
3+
#![allow(dead_code, unused_variables, clippy::print_literal)]
4+
5+
fn main() {
6+
// Consts
7+
const GOOD32: f32 = 0.123_456;
8+
const GOOD32_SM: f32 = 0.000_000_000_1;
9+
const GOOD32_DOT: f32 = 10_000_000_000.0;
10+
const GOOD32_EDGE: f32 = 1.000_000_8;
11+
const GOOD64: f64 = 0.123_456_789_012;
12+
const GOOD64_SM: f32 = 0.000_000_000_000_000_1;
13+
const GOOD64_DOT: f32 = 10_000_000_000_000_000.0;
14+
15+
const BAD32_1: f32 = 0.123_456_79;
16+
const BAD32_2: f32 = 0.123_456_79;
17+
const BAD32_3: f32 = 0.1;
18+
const BAD32_EDGE: f32 = 1.000_001;
19+
20+
const BAD64_1: f64 = 0.123_456_789_012_345_66;
21+
const BAD64_2: f64 = 0.123_456_789_012_345_66;
22+
const BAD64_3: f64 = 0.1;
23+
24+
// Literal as param
25+
println!("{:?}", 8.888_888_888_888_89);
26+
27+
// // TODO add inferred type tests for f32
28+
// Locals
29+
let good32: f32 = 0.123_456_f32;
30+
let good32_2: f32 = 0.123_456;
31+
32+
let good64: f64 = 0.123_456_789_012;
33+
let good64_suf: f64 = 0.123_456_789_012f64;
34+
let good64_inf = 0.123_456_789_012;
35+
36+
let bad32: f32 = 1.123_456_8;
37+
let bad32_suf: f32 = 1.123_456_8;
38+
let bad32_inf = 1.123_456_8;
39+
40+
let bad64: f64 = 0.123_456_789_012_345_66;
41+
let bad64_suf: f64 = 0.123_456_789_012_345_66;
42+
let bad64_inf = 0.123_456_789_012_345_66;
43+
44+
// Vectors
45+
let good_vec32: Vec<f32> = vec![0.123_456];
46+
let good_vec64: Vec<f64> = vec![0.123_456_789];
47+
48+
let bad_vec32: Vec<f32> = vec![0.123_456_79];
49+
let bad_vec64: Vec<f64> = vec![0.123_456_789_123_456_78];
50+
51+
// Exponential float notation
52+
let good_e32: f32 = 1e-10;
53+
let bad_e32: f32 = 1.123_456_8e-10;
54+
55+
let good_bige32: f32 = 1E-10;
56+
let bad_bige32: f32 = 1.123_456_8E-10;
57+
58+
// Inferred type
59+
let good_inferred: f32 = 1f32 * 1_000_000_000.;
60+
61+
// issue #2840
62+
let num = 0.000_000_000_01e-10f64;
63+
}

tests/ui/excessive_precision.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
// run-rustfix
12
#![warn(clippy::excessive_precision)]
2-
#![allow(clippy::print_literal)]
3+
#![allow(dead_code, unused_variables, clippy::print_literal)]
34

45
fn main() {
56
// Consts

tests/ui/excessive_precision.stderr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,109 @@
11
error: float has excessive precision
2-
--> $DIR/excessive_precision.rs:14:26
2+
--> $DIR/excessive_precision.rs:15:26
33
|
44
LL | const BAD32_1: f32 = 0.123_456_789_f32;
55
| ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79`
66
|
77
= note: `-D clippy::excessive-precision` implied by `-D warnings`
88

99
error: float has excessive precision
10-
--> $DIR/excessive_precision.rs:15:26
10+
--> $DIR/excessive_precision.rs:16:26
1111
|
1212
LL | const BAD32_2: f32 = 0.123_456_789;
1313
| ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79`
1414

1515
error: float has excessive precision
16-
--> $DIR/excessive_precision.rs:16:26
16+
--> $DIR/excessive_precision.rs:17:26
1717
|
1818
LL | const BAD32_3: f32 = 0.100_000_000_000_1;
1919
| ^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.1`
2020

2121
error: float has excessive precision
22-
--> $DIR/excessive_precision.rs:17:29
22+
--> $DIR/excessive_precision.rs:18:29
2323
|
2424
LL | const BAD32_EDGE: f32 = 1.000_000_9;
2525
| ^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.000_001`
2626

2727
error: float has excessive precision
28-
--> $DIR/excessive_precision.rs:19:26
28+
--> $DIR/excessive_precision.rs:20:26
2929
|
3030
LL | const BAD64_1: f64 = 0.123_456_789_012_345_67f64;
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
3232

3333
error: float has excessive precision
34-
--> $DIR/excessive_precision.rs:20:26
34+
--> $DIR/excessive_precision.rs:21:26
3535
|
3636
LL | const BAD64_2: f64 = 0.123_456_789_012_345_67;
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
3838

3939
error: float has excessive precision
40-
--> $DIR/excessive_precision.rs:21:26
40+
--> $DIR/excessive_precision.rs:22:26
4141
|
4242
LL | const BAD64_3: f64 = 0.100_000_000_000_000_000_1;
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.1`
4444

4545
error: float has excessive precision
46-
--> $DIR/excessive_precision.rs:24:22
46+
--> $DIR/excessive_precision.rs:25:22
4747
|
4848
LL | println!("{:?}", 8.888_888_888_888_888_888_888);
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `8.888_888_888_888_89`
5050

5151
error: float has excessive precision
52-
--> $DIR/excessive_precision.rs:35:22
52+
--> $DIR/excessive_precision.rs:36:22
5353
|
5454
LL | let bad32: f32 = 1.123_456_789;
5555
| ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8`
5656

5757
error: float has excessive precision
58-
--> $DIR/excessive_precision.rs:36:26
58+
--> $DIR/excessive_precision.rs:37:26
5959
|
6060
LL | let bad32_suf: f32 = 1.123_456_789_f32;
6161
| ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8`
6262

6363
error: float has excessive precision
64-
--> $DIR/excessive_precision.rs:37:21
64+
--> $DIR/excessive_precision.rs:38:21
6565
|
6666
LL | let bad32_inf = 1.123_456_789_f32;
6767
| ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8`
6868

6969
error: float has excessive precision
70-
--> $DIR/excessive_precision.rs:39:22
70+
--> $DIR/excessive_precision.rs:40:22
7171
|
7272
LL | let bad64: f64 = 0.123_456_789_012_345_67;
7373
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
7474

7575
error: float has excessive precision
76-
--> $DIR/excessive_precision.rs:40:26
76+
--> $DIR/excessive_precision.rs:41:26
7777
|
7878
LL | let bad64_suf: f64 = 0.123_456_789_012_345_67f64;
7979
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
8080

8181
error: float has excessive precision
82-
--> $DIR/excessive_precision.rs:41:21
82+
--> $DIR/excessive_precision.rs:42:21
8383
|
8484
LL | let bad64_inf = 0.123_456_789_012_345_67;
8585
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
8686

8787
error: float has excessive precision
88-
--> $DIR/excessive_precision.rs:47:36
88+
--> $DIR/excessive_precision.rs:48:36
8989
|
9090
LL | let bad_vec32: Vec<f32> = vec![0.123_456_789];
9191
| ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79`
9292

9393
error: float has excessive precision
94-
--> $DIR/excessive_precision.rs:48:36
94+
--> $DIR/excessive_precision.rs:49:36
9595
|
9696
LL | let bad_vec64: Vec<f64> = vec![0.123_456_789_123_456_789];
9797
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_123_456_78`
9898

9999
error: float has excessive precision
100-
--> $DIR/excessive_precision.rs:52:24
100+
--> $DIR/excessive_precision.rs:53:24
101101
|
102102
LL | let bad_e32: f32 = 1.123_456_788_888e-10;
103103
| ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8e-10`
104104

105105
error: float has excessive precision
106-
--> $DIR/excessive_precision.rs:55:27
106+
--> $DIR/excessive_precision.rs:56:27
107107
|
108108
LL | let bad_bige32: f32 = 1.123_456_788_888E-10;
109109
| ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8E-10`

0 commit comments

Comments
 (0)