Skip to content

Commit 78695bd

Browse files
Do not lint float fractions in mistyped_literal_suffixes (fixes #4706)
1 parent 2ed5143 commit 78695bd

File tree

4 files changed

+10
-25
lines changed

4 files changed

+10
-25
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-rustfix
22

3-
#![allow(dead_code, unused_variables, clippy::excessive_precision)]
3+
#![allow(dead_code, unused_variables, clippy::excessive_precision, clippy::inconsistent_digit_grouping)]
44

55
fn main() {
66
let fail14 = 2_i32;
@@ -12,13 +12,13 @@ fn main() {
1212
let fail20 = 2_i8; //
1313
let fail21 = 4_i16; //
1414

15-
let fail24 = 12.34_f64;
15+
let ok24 = 12.34_64;
1616
let fail25 = 1E2_f32;
1717
let fail26 = 43E7_f64;
1818
let fail27 = 243E17_f32;
1919
#[allow(overflowing_literals)]
2020
let fail28 = 241_251_235E723_f64;
21-
let fail29 = 42_279.911_f32;
21+
let ok29 = 42279.911_32;
2222

2323
let _ = 1.123_45E1_f32;
2424
}

tests/ui/mistyped_literal_suffix.rs

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

3-
#![allow(dead_code, unused_variables, clippy::excessive_precision)]
3+
#![allow(dead_code, unused_variables, clippy::excessive_precision, clippy::inconsistent_digit_grouping)]
44

55
fn main() {
66
let fail14 = 2_32;
@@ -12,13 +12,13 @@ fn main() {
1212
let fail20 = 2__8; //
1313
let fail21 = 4___16; //
1414

15-
let fail24 = 12.34_64;
15+
let ok24 = 12.34_64;
1616
let fail25 = 1E2_32;
1717
let fail26 = 43E7_64;
1818
let fail27 = 243E17_32;
1919
#[allow(overflowing_literals)]
2020
let fail28 = 241251235E723_64;
21-
let fail29 = 42279.911_32;
21+
let ok29 = 42279.911_32;
2222

2323
let _ = 1.12345E1_32;
2424
}

tests/ui/mistyped_literal_suffix.stderr

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ error: mistyped literal suffix
3636
LL | let fail21 = 4___16; //
3737
| ^^^^^^ help: did you mean to write: `4_i16`
3838

39-
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-
4539
error: mistyped literal suffix
4640
--> $DIR/mistyped_literal_suffix.rs:16:18
4741
|
@@ -66,17 +60,11 @@ error: mistyped literal suffix
6660
LL | let fail28 = 241251235E723_64;
6761
| ^^^^^^^^^^^^^^^^ help: did you mean to write: `241_251_235E723_f64`
6862

69-
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-
7563
error: mistyped literal suffix
7664
--> $DIR/mistyped_literal_suffix.rs:23: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)