about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2021-01-24 22:09:51 +0100
committerGitHub <noreply@github.com>2021-01-24 22:09:51 +0100
commit3ed8a3769aef987d437b09e7285b5d0c46c97a94 (patch)
tree7c7ca3b2f4283630ac4d56cbce65076483c4f029
parent13b88c21d002bdd84395cb30c28bc6460afc2315 (diff)
parentc387e29e9139096f8afc237b2dd1a49f32635bea (diff)
downloadrust-3ed8a3769aef987d437b09e7285b5d0c46c97a94.tar.gz
rust-3ed8a3769aef987d437b09e7285b5d0c46c97a94.zip
Rollup merge of #79884 - Digital-Chaos:replace-magic, r=m-ou-se
Replace magic numbers with existing constants

Replaced magic numbers in `library/core/src/time.rs` with predefined constants.
-rw-r--r--library/core/src/time.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/library/core/src/time.rs b/library/core/src/time.rs
index 88b4e2a2436..b1443bc33d2 100644
--- a/library/core/src/time.rs
+++ b/library/core/src/time.rs
@@ -1067,13 +1067,23 @@ impl fmt::Debug for Duration {
         }
 
         if self.secs > 0 {
-            fmt_decimal(f, self.secs, self.nanos, 100_000_000)?;
+            fmt_decimal(f, self.secs, self.nanos, NANOS_PER_SEC / 10)?;
             f.write_str("s")
-        } else if self.nanos >= 1_000_000 {
-            fmt_decimal(f, self.nanos as u64 / 1_000_000, self.nanos % 1_000_000, 100_000)?;
+        } else if self.nanos >= NANOS_PER_MILLI {
+            fmt_decimal(
+                f,
+                (self.nanos / NANOS_PER_MILLI) as u64,
+                self.nanos % NANOS_PER_MILLI,
+                NANOS_PER_MILLI / 10,
+            )?;
             f.write_str("ms")
-        } else if self.nanos >= 1_000 {
-            fmt_decimal(f, self.nanos as u64 / 1_000, self.nanos % 1_000, 100)?;
+        } else if self.nanos >= NANOS_PER_MICRO {
+            fmt_decimal(
+                f,
+                (self.nanos / NANOS_PER_MICRO) as u64,
+                self.nanos % NANOS_PER_MICRO,
+                NANOS_PER_MICRO / 10,
+            )?;
             f.write_str("µs")
         } else {
             fmt_decimal(f, self.nanos as u64, 0, 1)?;