Skip to content

Commit 3239b46

Browse files
committed
Auto merge of rust-lang#6114 - FliegendeWurst:no-mistyped-fraction, r=Manishearth
Do not lint float fractions in `mistyped_literal_suffixes` As suggested in rust-lang/rust-clippy#4706 (comment), the fractional part is now ignored (the integer part is checked instead). Fixes: rust-lang#4706 changelog: `mistyped_literal_suffixes` no longer warns on the fractional part of a float (e.g. 713.23_64)
2 parents 411e3ba + 428ef36 commit 3239b46

File tree

4 files changed

+31
-36
lines changed

4 files changed

+31
-36
lines changed

clippy_lints/src/literal_representation.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,10 @@ impl LiteralDigitGrouping {
264264

265265
let (part, mistyped_suffixes, missing_char) = if let Some((_, exponent)) = &mut num_lit.exponent {
266266
(exponent, &["32", "64"][..], 'f')
267+
} else if num_lit.fraction.is_some() {
268+
(&mut num_lit.integer, &["32", "64"][..], 'f')
267269
} else {
268-
num_lit
269-
.fraction
270-
.as_mut()
271-
.map_or((&mut num_lit.integer, &["8", "16", "32", "64"][..], 'i'), |fraction| {
272-
(fraction, &["32", "64"][..], 'f')
273-
})
270+
(&mut num_lit.integer, &["8", "16", "32", "64"][..], 'i')
274271
};
275272

276273
let mut split = part.rsplit('_');

tests/ui/mistyped_literal_suffix.fixed

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// run-rustfix
22

3-
#![allow(dead_code, unused_variables, clippy::excessive_precision)]
3+
#![allow(
4+
dead_code,
5+
unused_variables,
6+
clippy::excessive_precision,
7+
clippy::inconsistent_digit_grouping
8+
)]
49

510
fn main() {
611
let fail14 = 2_i32;
@@ -12,13 +17,13 @@ fn main() {
1217
let fail20 = 2_i8; //
1318
let fail21 = 4_i16; //
1419

15-
let fail24 = 12.34_f64;
20+
let ok24 = 12.34_64;
1621
let fail25 = 1E2_f32;
1722
let fail26 = 43E7_f64;
1823
let fail27 = 243E17_f32;
1924
#[allow(overflowing_literals)]
2025
let fail28 = 241_251_235E723_f64;
21-
let fail29 = 42_279.911_f32;
26+
let ok29 = 42279.911_32;
2227

2328
let _ = 1.123_45E1_f32;
2429
}

tests/ui/mistyped_literal_suffix.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// run-rustfix
22

3-
#![allow(dead_code, unused_variables, clippy::excessive_precision)]
3+
#![allow(
4+
dead_code,
5+
unused_variables,
6+
clippy::excessive_precision,
7+
clippy::inconsistent_digit_grouping
8+
)]
49

510
fn main() {
611
let fail14 = 2_32;
@@ -12,13 +17,13 @@ fn main() {
1217
let fail20 = 2__8; //
1318
let fail21 = 4___16; //
1419

15-
let fail24 = 12.34_64;
20+
let ok24 = 12.34_64;
1621
let fail25 = 1E2_32;
1722
let fail26 = 43E7_64;
1823
let fail27 = 243E17_32;
1924
#[allow(overflowing_literals)]
2025
let fail28 = 241251235E723_64;
21-
let fail29 = 42279.911_32;
26+
let ok29 = 42279.911_32;
2227

2328
let _ = 1.12345E1_32;
2429
}
Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,70 @@
11
error: mistyped literal suffix
2-
--> $DIR/mistyped_literal_suffix.rs:6:18
2+
--> $DIR/mistyped_literal_suffix.rs:11:18
33
|
44
LL | let fail14 = 2_32;
55
| ^^^^ help: did you mean to write: `2_i32`
66
|
77
= note: `#[deny(clippy::mistyped_literal_suffixes)]` on by default
88

99
error: mistyped literal suffix
10-
--> $DIR/mistyped_literal_suffix.rs:7:18
10+
--> $DIR/mistyped_literal_suffix.rs:12:18
1111
|
1212
LL | let fail15 = 4_64;
1313
| ^^^^ help: did you mean to write: `4_i64`
1414

1515
error: mistyped literal suffix
16-
--> $DIR/mistyped_literal_suffix.rs:8:18
16+
--> $DIR/mistyped_literal_suffix.rs:13:18
1717
|
1818
LL | let fail16 = 7_8; //
1919
| ^^^ help: did you mean to write: `7_i8`
2020

2121
error: mistyped literal suffix
22-
--> $DIR/mistyped_literal_suffix.rs:9:18
22+
--> $DIR/mistyped_literal_suffix.rs:14:18
2323
|
2424
LL | let fail17 = 23_16; //
2525
| ^^^^^ help: did you mean to write: `23_i16`
2626

2727
error: mistyped literal suffix
28-
--> $DIR/mistyped_literal_suffix.rs:12:18
28+
--> $DIR/mistyped_literal_suffix.rs:17:18
2929
|
3030
LL | let fail20 = 2__8; //
3131
| ^^^^ help: did you mean to write: `2_i8`
3232

3333
error: mistyped literal suffix
34-
--> $DIR/mistyped_literal_suffix.rs:13:18
34+
--> $DIR/mistyped_literal_suffix.rs:18:18
3535
|
3636
LL | let fail21 = 4___16; //
3737
| ^^^^^^ help: did you mean to write: `4_i16`
3838

3939
error: mistyped literal suffix
40-
--> $DIR/mistyped_literal_suffix.rs:15:18
41-
|
42-
LL | let fail24 = 12.34_64;
43-
| ^^^^^^^^ help: did you mean to write: `12.34_f64`
44-
45-
error: mistyped literal suffix
46-
--> $DIR/mistyped_literal_suffix.rs:16:18
40+
--> $DIR/mistyped_literal_suffix.rs:21:18
4741
|
4842
LL | let fail25 = 1E2_32;
4943
| ^^^^^^ help: did you mean to write: `1E2_f32`
5044

5145
error: mistyped literal suffix
52-
--> $DIR/mistyped_literal_suffix.rs:17:18
46+
--> $DIR/mistyped_literal_suffix.rs:22:18
5347
|
5448
LL | let fail26 = 43E7_64;
5549
| ^^^^^^^ help: did you mean to write: `43E7_f64`
5650

5751
error: mistyped literal suffix
58-
--> $DIR/mistyped_literal_suffix.rs:18:18
52+
--> $DIR/mistyped_literal_suffix.rs:23:18
5953
|
6054
LL | let fail27 = 243E17_32;
6155
| ^^^^^^^^^ help: did you mean to write: `243E17_f32`
6256

6357
error: mistyped literal suffix
64-
--> $DIR/mistyped_literal_suffix.rs:20:18
58+
--> $DIR/mistyped_literal_suffix.rs:25:18
6559
|
6660
LL | let fail28 = 241251235E723_64;
6761
| ^^^^^^^^^^^^^^^^ help: did you mean to write: `241_251_235E723_f64`
6862

6963
error: mistyped literal suffix
70-
--> $DIR/mistyped_literal_suffix.rs:21:18
71-
|
72-
LL | let fail29 = 42279.911_32;
73-
| ^^^^^^^^^^^^ help: did you mean to write: `42_279.911_f32`
74-
75-
error: mistyped literal suffix
76-
--> $DIR/mistyped_literal_suffix.rs:23:13
64+
--> $DIR/mistyped_literal_suffix.rs:28:13
7765
|
7866
LL | let _ = 1.12345E1_32;
7967
| ^^^^^^^^^^^^ help: did you mean to write: `1.123_45E1_f32`
8068

81-
error: aborting due to 13 previous errors
69+
error: aborting due to 11 previous errors
8270

0 commit comments

Comments
 (0)