Skip to content

Commit b440028

Browse files
committed
Addressed comments
1 parent 201f1d6 commit b440028

File tree

9 files changed

+79
-32
lines changed

9 files changed

+79
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6712,7 +6712,7 @@ Released 2018-09-13
67126712
[`check-inconsistent-struct-field-initializers`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-inconsistent-struct-field-initializers
67136713
[`check-private-items`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-private-items
67146714
[`cognitive-complexity-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#cognitive-complexity-threshold
6715-
[`const-literal-precision-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#const-literal-precision-threshold
6715+
[`const-literal-digits-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#const-literal-digits-threshold
67166716
[`disallowed-macros`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-macros
67176717
[`disallowed-methods`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-methods
67186718
[`disallowed-names`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-names

book/src/lint_configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,10 @@ The maximum cognitive complexity a function can have
485485
* [`cognitive_complexity`](https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity)
486486

487487

488-
## `const-literal-precision-threshold`
488+
## `const-literal-digits-threshold`
489489
The minimum digits a const float literal must have to supress the `excessive_precicion` lint
490490

491-
**Default Value:** `40`
491+
**Default Value:** `30`
492492

493493
---
494494
**Affected lints:**

clippy_config/src/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ define_Conf! {
572572
cognitive_complexity_threshold: u64 = 25,
573573
/// The minimum digits a const float literal must have to supress the `excessive_precicion` lint
574574
#[lints(excessive_precision)]
575-
const_literal_precision_threshold: usize = 40,
575+
const_literal_digits_threshold: usize = 30,
576576
/// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY.
577577
///
578578
/// Use the Cognitive Complexity lint instead.

clippy_lints/src/float_literal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl_lint_pass!(FloatLiteral => [
7272
impl FloatLiteral {
7373
pub fn new(conf: &'static Conf) -> Self {
7474
Self {
75-
const_literal_precision_threshold: conf.const_literal_precision_threshold,
75+
const_literal_precision_threshold: conf.const_literal_digits_threshold,
7676
}
7777
}
7878
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
const-literal-precision-threshold = 20
1+
const-literal-digits-threshold = 20

tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
3535
check-inconsistent-struct-field-initializers
3636
check-private-items
3737
cognitive-complexity-threshold
38-
const-literal-precision-threshold
38+
const-literal-digits-threshold
3939
disallowed-macros
4040
disallowed-methods
4141
disallowed-names
@@ -130,7 +130,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
130130
check-inconsistent-struct-field-initializers
131131
check-private-items
132132
cognitive-complexity-threshold
133-
const-literal-precision-threshold
133+
const-literal-digits-threshold
134134
disallowed-macros
135135
disallowed-methods
136136
disallowed-names
@@ -225,7 +225,7 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
225225
check-inconsistent-struct-field-initializers
226226
check-private-items
227227
cognitive-complexity-threshold
228-
const-literal-precision-threshold
228+
const-literal-digits-threshold
229229
disallowed-macros
230230
disallowed-methods
231231
disallowed-names

tests/ui/excessive_precision.fixed

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@
44
overflowing_literals,
55
unused_variables,
66
clippy::print_literal,
7-
clippy::useless_vec
7+
clippy::useless_vec,
8+
clippy::approx_constant
89
)]
910

11+
macro_rules! make_pi {
12+
($i:ident : $t:ty) => {
13+
const $i: $t = 3.14159265358979323846264338327950288419716939937510582097494459230781640628;
14+
};
15+
}
16+
1017
fn main() {
1118
// Consts
1219
const GOOD32: f32 = 0.123_456;
@@ -115,6 +122,14 @@ fn main() {
115122

116123
static mut STATIC_MUT1: f32 = 1.01234567890123456789012345678901234567890;
117124
static mut STATIC_MUT2: f64 = 1.01234567890123456789012345678901234567890;
125+
126+
// From issue #13855
127+
let gamma = 0.577_215_664_901_532_9;
128+
//~^ excessive_precision
129+
const GAMMA: f64 = 0.5772156649015328606065120900824024310421;
130+
131+
make_pi!(P32: f32);
132+
make_pi!(P64: f64);
118133
}
119134

120135
trait ExcessivelyPreciseTrait {

tests/ui/excessive_precision.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@
44
overflowing_literals,
55
unused_variables,
66
clippy::print_literal,
7-
clippy::useless_vec
7+
clippy::useless_vec,
8+
clippy::approx_constant
89
)]
910

11+
macro_rules! make_pi {
12+
($i:ident : $t:ty) => {
13+
const $i: $t = 3.14159265358979323846264338327950288419716939937510582097494459230781640628;
14+
};
15+
}
16+
1017
fn main() {
1118
// Consts
1219
const GOOD32: f32 = 0.123_456;
@@ -115,6 +122,14 @@ fn main() {
115122

116123
static mut STATIC_MUT1: f32 = 1.01234567890123456789012345678901234567890;
117124
static mut STATIC_MUT2: f64 = 1.01234567890123456789012345678901234567890;
125+
126+
// From issue #13855
127+
let gamma = 0.5772156649015328606065120900824024310421;
128+
//~^ excessive_precision
129+
const GAMMA: f64 = 0.5772156649015328606065120900824024310421;
130+
131+
make_pi!(P32: f32);
132+
make_pi!(P64: f64);
118133
}
119134

120135
trait ExcessivelyPreciseTrait {

tests/ui/excessive_precision.stderr

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: float has excessive precision
2-
--> tests/ui/excessive_precision.rs:20:26
2+
--> tests/ui/excessive_precision.rs:27:26
33
|
44
LL | const BAD32_1: f32 = 0.123_456_789_f32;
55
| ^^^^^^^^^^^^^^^^^
@@ -13,7 +13,7 @@ LL + const BAD32_1: f32 = 0.123_456_79_f32;
1313
|
1414

1515
error: float has excessive precision
16-
--> tests/ui/excessive_precision.rs:22:26
16+
--> tests/ui/excessive_precision.rs:29:26
1717
|
1818
LL | const BAD32_2: f32 = 0.123_456_789;
1919
| ^^^^^^^^^^^^^
@@ -25,7 +25,7 @@ LL + const BAD32_2: f32 = 0.123_456_79;
2525
|
2626

2727
error: float has excessive precision
28-
--> tests/ui/excessive_precision.rs:24:26
28+
--> tests/ui/excessive_precision.rs:31:26
2929
|
3030
LL | const BAD32_3: f32 = 0.100_000_000_000_1;
3131
| ^^^^^^^^^^^^^^^^^^^
@@ -37,7 +37,7 @@ LL + const BAD32_3: f32 = 0.1;
3737
|
3838

3939
error: float has excessive precision
40-
--> tests/ui/excessive_precision.rs:26:29
40+
--> tests/ui/excessive_precision.rs:33:29
4141
|
4242
LL | const BAD32_EDGE: f32 = 1.000_000_9;
4343
| ^^^^^^^^^^^
@@ -49,7 +49,7 @@ LL + const BAD32_EDGE: f32 = 1.000_001;
4949
|
5050

5151
error: float has excessive precision
52-
--> tests/ui/excessive_precision.rs:31:26
52+
--> tests/ui/excessive_precision.rs:38:26
5353
|
5454
LL | const BAD64_3: f64 = 0.100_000_000_000_000_000_1;
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -61,7 +61,7 @@ LL + const BAD64_3: f64 = 0.1;
6161
|
6262

6363
error: float has excessive precision
64-
--> tests/ui/excessive_precision.rs:35:22
64+
--> tests/ui/excessive_precision.rs:42:22
6565
|
6666
LL | println!("{:?}", 8.888_888_888_888_888_888_888);
6767
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -73,7 +73,7 @@ LL + println!("{:?}", 8.888_888_888_888_89);
7373
|
7474

7575
error: float has excessive precision
76-
--> tests/ui/excessive_precision.rs:47:22
76+
--> tests/ui/excessive_precision.rs:54:22
7777
|
7878
LL | let bad32: f32 = 1.123_456_789;
7979
| ^^^^^^^^^^^^^
@@ -85,7 +85,7 @@ LL + let bad32: f32 = 1.123_456_8;
8585
|
8686

8787
error: float has excessive precision
88-
--> tests/ui/excessive_precision.rs:49:26
88+
--> tests/ui/excessive_precision.rs:56:26
8989
|
9090
LL | let bad32_suf: f32 = 1.123_456_789_f32;
9191
| ^^^^^^^^^^^^^^^^^
@@ -97,7 +97,7 @@ LL + let bad32_suf: f32 = 1.123_456_8_f32;
9797
|
9898

9999
error: float has excessive precision
100-
--> tests/ui/excessive_precision.rs:51:21
100+
--> tests/ui/excessive_precision.rs:58:21
101101
|
102102
LL | let bad32_inf = 1.123_456_789_f32;
103103
| ^^^^^^^^^^^^^^^^^
@@ -109,7 +109,7 @@ LL + let bad32_inf = 1.123_456_8_f32;
109109
|
110110

111111
error: float has excessive precision
112-
--> tests/ui/excessive_precision.rs:62:36
112+
--> tests/ui/excessive_precision.rs:69:36
113113
|
114114
LL | let bad_vec32: Vec<f32> = vec![0.123_456_789];
115115
| ^^^^^^^^^^^^^
@@ -121,7 +121,7 @@ LL + let bad_vec32: Vec<f32> = vec![0.123_456_79];
121121
|
122122

123123
error: float has excessive precision
124-
--> tests/ui/excessive_precision.rs:64:36
124+
--> tests/ui/excessive_precision.rs:71:36
125125
|
126126
LL | let bad_vec64: Vec<f64> = vec![0.123_456_789_123_456_789];
127127
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -133,7 +133,7 @@ LL + let bad_vec64: Vec<f64> = vec![0.123_456_789_123_456_78];
133133
|
134134

135135
error: float has excessive precision
136-
--> tests/ui/excessive_precision.rs:69:24
136+
--> tests/ui/excessive_precision.rs:76:24
137137
|
138138
LL | let bad_e32: f32 = 1.123_456_788_888e-10;
139139
| ^^^^^^^^^^^^^^^^^^^^^
@@ -145,7 +145,7 @@ LL + let bad_e32: f32 = 1.123_456_8e-10;
145145
|
146146

147147
error: float has excessive precision
148-
--> tests/ui/excessive_precision.rs:73:27
148+
--> tests/ui/excessive_precision.rs:80:27
149149
|
150150
LL | let bad_bige32: f32 = 1.123_456_788_888E-10;
151151
| ^^^^^^^^^^^^^^^^^^^^^
@@ -157,7 +157,7 @@ LL + let bad_bige32: f32 = 1.123_456_8E-10;
157157
|
158158

159159
error: float has excessive precision
160-
--> tests/ui/excessive_precision.rs:86:13
160+
--> tests/ui/excessive_precision.rs:93:13
161161
|
162162
LL | let _ = 2.225_073_858_507_201_1e-308_f64;
163163
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -169,7 +169,7 @@ LL + let _ = 2.225_073_858_507_201e-308_f64;
169169
|
170170

171171
error: float has excessive precision
172-
--> tests/ui/excessive_precision.rs:90:13
172+
--> tests/ui/excessive_precision.rs:97:13
173173
|
174174
LL | let _ = 1.000_000_000_000_001e-324_f64;
175175
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -181,7 +181,7 @@ LL + let _ = 0_f64;
181181
|
182182

183183
error: float has excessive precision
184-
--> tests/ui/excessive_precision.rs:101:20
184+
--> tests/ui/excessive_precision.rs:108:20
185185
|
186186
LL | const _: f64 = 3.0000000000000000e+00;
187187
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -193,13 +193,13 @@ LL + const _: f64 = 3.0;
193193
|
194194

195195
error: float has excessive precision
196-
--> tests/ui/excessive_precision.rs:106:18
196+
--> tests/ui/excessive_precision.rs:113:18
197197
|
198198
LL | let _: f32 = 1.01234567890123456789012345678901234567890;
199199
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
200200
|
201201
note: consider making it a `const` item
202-
--> tests/ui/excessive_precision.rs:106:5
202+
--> tests/ui/excessive_precision.rs:113:5
203203
|
204204
LL | let _: f32 = 1.01234567890123456789012345678901234567890;
205205
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -210,13 +210,13 @@ LL + let _: f32 = 1.012_345_7;
210210
|
211211

212212
error: float has excessive precision
213-
--> tests/ui/excessive_precision.rs:108:18
213+
--> tests/ui/excessive_precision.rs:115:18
214214
|
215215
LL | let _: f64 = 1.01234567890123456789012345678901234567890;
216216
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
217217
|
218218
note: consider making it a `const` item
219-
--> tests/ui/excessive_precision.rs:108:5
219+
--> tests/ui/excessive_precision.rs:115:5
220220
|
221221
LL | let _: f64 = 1.01234567890123456789012345678901234567890;
222222
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -226,5 +226,22 @@ LL - let _: f64 = 1.01234567890123456789012345678901234567890;
226226
LL + let _: f64 = 1.012_345_678_901_234_6;
227227
|
228228

229-
error: aborting due to 18 previous errors
229+
error: float has excessive precision
230+
--> tests/ui/excessive_precision.rs:127:17
231+
|
232+
LL | let gamma = 0.5772156649015328606065120900824024310421;
233+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
234+
|
235+
note: consider making it a `const` item
236+
--> tests/ui/excessive_precision.rs:127:5
237+
|
238+
LL | let gamma = 0.5772156649015328606065120900824024310421;
239+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
240+
help: consider changing the type or truncating it to
241+
|
242+
LL - let gamma = 0.5772156649015328606065120900824024310421;
243+
LL + let gamma = 0.577_215_664_901_532_9;
244+
|
245+
246+
error: aborting due to 19 previous errors
230247

0 commit comments

Comments
 (0)