Auto merge of #7774 - dswij:useless-exponent, r=llogiq

Useless exponent

Closes #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
This commit is contained in:
bors 2021-10-06 07:54:27 +00:00
commit c6b915825f
4 changed files with 17 additions and 3 deletions

View file

@ -157,9 +157,11 @@ impl<'a> NumericLiteral<'a> {
} }
if let Some((separator, exponent)) = self.exponent { if let Some((separator, exponent)) = self.exponent {
if exponent != "0" {
output.push_str(separator); output.push_str(separator);
Self::group_digits(&mut output, exponent, group_size, true, false); Self::group_digits(&mut output, exponent, group_size, true, false);
} }
}
if let Some(suffix) = self.suffix { if let Some(suffix) = self.suffix {
if output.ends_with('.') { if output.ends_with('.') {

View file

@ -63,4 +63,7 @@ fn main() {
// issue #7744 // issue #7744
let _ = 2.225_073_858_507_201e-308_f64; let _ = 2.225_073_858_507_201e-308_f64;
// issue #7745
let _ = 0_f64;
} }

View file

@ -63,4 +63,7 @@ fn main() {
// issue #7744 // issue #7744
let _ = 2.225_073_858_507_201_1e-308_f64; let _ = 2.225_073_858_507_201_1e-308_f64;
// issue #7745
let _ = 1.000_000_000_000_001e-324_f64;
} }

View file

@ -84,5 +84,11 @@ error: float has excessive precision
LL | let _ = 2.225_073_858_507_201_1e-308_f64; LL | let _ = 2.225_073_858_507_201_1e-308_f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `2.225_073_858_507_201e-308_f64` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `2.225_073_858_507_201e-308_f64`
error: aborting due to 14 previous errors error: float has excessive precision
--> $DIR/excessive_precision.rs:68:13
|
LL | let _ = 1.000_000_000_000_001e-324_f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0_f64`
error: aborting due to 15 previous errors