Skip to content

Commit 4cb16e6

Browse files
authored
Merge pull request #3238 from JoshMcguigan/excessive_precision-3180
Fixes #3180, suppress excessive_precision lint for floats with no decimal part
2 parents 67d85bc + e25f884 commit 4cb16e6

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

clippy_lints/src/excessive_precision.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ impl ExcessivePrecision {
9898
}
9999
}
100100

101-
/// Should we exclude the float because it has a .0 suffix
101+
/// Should we exclude the float because it has a `.0` or `.` suffix
102102
/// Ex 1_000_000_000.0
103+
/// Ex 1_000_000_000.
103104
fn dot_zero_exclusion(s: &str) -> bool {
104105
if let Some(after_dec) = s.split('.').nth(1) {
105106
let mut decpart = after_dec
@@ -108,7 +109,8 @@ fn dot_zero_exclusion(s: &str) -> bool {
108109

109110
match decpart.next() {
110111
Some('0') => decpart.count() == 0,
111-
_ => false,
112+
Some(_) => false,
113+
None => true,
112114
}
113115
} else {
114116
false

tests/ui/excessive_precision.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ fn main() {
5454

5555
let good_bige32: f32 = 1E-10;
5656
let bad_bige32: f32 = 1.123_456_788_888E-10;
57+
58+
// Inferred type
59+
let good_inferred: f32 = 1f32 * 1_000_000_000.;
5760
}

0 commit comments

Comments
 (0)