about summary refs log tree commit diff
path: root/library/core/src
diff options
context:
space:
mode:
authorGeorge Bateman <george.bateman16@gmail.com>2024-10-14 20:47:24 +0100
committerGeorge Bateman <george.bateman16@gmail.com>2024-10-14 20:50:40 +0100
commit4e438f7d6b7f6fbf2bb0c1ffe6ffe0b6bfc7fa38 (patch)
tree8d572d6a1a00754a0c12e3f562747cfd5289e78d /library/core/src
parent17a19e684cdf3ca088af8b4da6a6209d128913f4 (diff)
downloadrust-4e438f7d6b7f6fbf2bb0c1ffe6ffe0b6bfc7fa38.tar.gz
rust-4e438f7d6b7f6fbf2bb0c1ffe6ffe0b6bfc7fa38.zip
Fix two const-hacks
Diffstat (limited to 'library/core/src')
-rw-r--r--library/core/src/time.rs8
1 files changed, 3 insertions, 5 deletions
diff --git a/library/core/src/time.rs b/library/core/src/time.rs
index f7ea7e06e9c..51005ff795c 100644
--- a/library/core/src/time.rs
+++ b/library/core/src/time.rs
@@ -213,11 +213,9 @@ impl Duration {
             // SAFETY: nanos < NANOS_PER_SEC, therefore nanos is within the valid range
             Duration { secs, nanos: unsafe { Nanoseconds(nanos) } }
         } else {
-            // FIXME(const-hack): use `.expect` once that is possible.
-            let secs = match secs.checked_add((nanos / NANOS_PER_SEC) as u64) {
-                Some(secs) => secs,
-                None => panic!("overflow in Duration::new"),
-            };
+            let secs = secs
+                .checked_add((nanos / NANOS_PER_SEC) as u64)
+                .expect("overflow in Duration::new");
             let nanos = nanos % NANOS_PER_SEC;
             // SAFETY: nanos % NANOS_PER_SEC < NANOS_PER_SEC, therefore nanos is within the valid range
             Duration { secs, nanos: unsafe { Nanoseconds(nanos) } }