Skip to content

Commit 3ed8a37

Browse files
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.
2 parents 13b88c2 + c387e29 commit 3ed8a37

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

library/core/src/time.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -1067,13 +1067,23 @@ impl fmt::Debug for Duration {
10671067
}
10681068

10691069
if self.secs > 0 {
1070-
fmt_decimal(f, self.secs, self.nanos, 100_000_000)?;
1070+
fmt_decimal(f, self.secs, self.nanos, NANOS_PER_SEC / 10)?;
10711071
f.write_str("s")
1072-
} else if self.nanos >= 1_000_000 {
1073-
fmt_decimal(f, self.nanos as u64 / 1_000_000, self.nanos % 1_000_000, 100_000)?;
1072+
} else if self.nanos >= NANOS_PER_MILLI {
1073+
fmt_decimal(
1074+
f,
1075+
(self.nanos / NANOS_PER_MILLI) as u64,
1076+
self.nanos % NANOS_PER_MILLI,
1077+
NANOS_PER_MILLI / 10,
1078+
)?;
10741079
f.write_str("ms")
1075-
} else if self.nanos >= 1_000 {
1076-
fmt_decimal(f, self.nanos as u64 / 1_000, self.nanos % 1_000, 100)?;
1080+
} else if self.nanos >= NANOS_PER_MICRO {
1081+
fmt_decimal(
1082+
f,
1083+
(self.nanos / NANOS_PER_MICRO) as u64,
1084+
self.nanos % NANOS_PER_MICRO,
1085+
NANOS_PER_MICRO / 10,
1086+
)?;
10771087
f.write_str("µs")
10781088
} else {
10791089
fmt_decimal(f, self.nanos as u64, 0, 1)?;

0 commit comments

Comments
 (0)