Skip to content

Commit c6b9158

Browse files
committed
Auto merge of rust-lang#7774 - dswij:useless-exponent, r=llogiq
Useless exponent Closes rust-lang#7745 I'm open to some thoughts on dropping the exponents on suggestions when it's zero. I personally don't see any problem on this. changelog: [`useless_exponent`] suggestion drops exponent when exponent value is zero
2 parents 871b8b5 + e476d05 commit c6b9158

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

clippy_utils/src/numeric_literal.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ impl<'a> NumericLiteral<'a> {
157157
}
158158

159159
if let Some((separator, exponent)) = self.exponent {
160-
output.push_str(separator);
161-
Self::group_digits(&mut output, exponent, group_size, true, false);
160+
if exponent != "0" {
161+
output.push_str(separator);
162+
Self::group_digits(&mut output, exponent, group_size, true, false);
163+
}
162164
}
163165

164166
if let Some(suffix) = self.suffix {

tests/ui/excessive_precision.fixed

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

6464
// issue #7744
6565
let _ = 2.225_073_858_507_201e-308_f64;
66+
67+
// issue #7745
68+
let _ = 0_f64;
6669
}

tests/ui/excessive_precision.rs

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

6464
// issue #7744
6565
let _ = 2.225_073_858_507_201_1e-308_f64;
66+
67+
// issue #7745
68+
let _ = 1.000_000_000_000_001e-324_f64;
6669
}

tests/ui/excessive_precision.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,11 @@ error: float has excessive precision
8484
LL | let _ = 2.225_073_858_507_201_1e-308_f64;
8585
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `2.225_073_858_507_201e-308_f64`
8686

87-
error: aborting due to 14 previous errors
87+
error: float has excessive precision
88+
--> $DIR/excessive_precision.rs:68:13
89+
|
90+
LL | let _ = 1.000_000_000_000_001e-324_f64;
91+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0_f64`
92+
93+
error: aborting due to 15 previous errors
8894

0 commit comments

Comments
 (0)