about summary refs log tree commit diff
path: root/library/std/tests
diff options
context:
space:
mode:
authorStepan Koltsov <stepan.koltsov@gmail.com>2025-09-24 20:32:50 +0100
committerStepan Koltsov <stepan.koltsov@gmail.com>2025-09-24 21:07:26 +0100
commit92859e98ee1a2101df8322a8581e4d638eb15078 (patch)
tree8f86a2f4a44504ca920b5a3116ea001a17b5c98a /library/std/tests
parent15283f6fe95e5b604273d13a428bab5fc0788f5a (diff)
downloadrust-92859e98ee1a2101df8322a8581e4d638eb15078.tar.gz
rust-92859e98ee1a2101df8322a8581e4d638eb15078.zip
Repro duration_since regression from issue 146228
Diffstat (limited to 'library/std/tests')
-rw-r--r--library/std/tests/time.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/library/std/tests/time.rs b/library/std/tests/time.rs
index 40709eae37c..be1948af915 100644
--- a/library/std/tests/time.rs
+++ b/library/std/tests/time.rs
@@ -227,3 +227,19 @@ fn big_math() {
     check(instant.checked_add(Duration::from_secs(100)), Instant::checked_sub);
     check(instant.checked_add(Duration::from_secs(i64::MAX as _)), Instant::checked_sub);
 }
+
+#[test]
+#[cfg(unix)]
+fn system_time_duration_since_max_range_on_unix() {
+    // Repro regression https://github.com/rust-lang/rust/issues/146228
+
+    // Min and max values of `SystemTime` on Unix.
+    let min = SystemTime::UNIX_EPOCH - (Duration::new(i64::MAX as u64 + 1, 0));
+    let max = SystemTime::UNIX_EPOCH + (Duration::new(i64::MAX as u64, 999_999_999));
+
+    let delta_a = max.duration_since(min).expect("duration_since overflow");
+    let delta_b = min.duration_since(max).expect_err("duration_since overflow").duration();
+
+    assert_eq!(Duration::MAX, delta_a);
+    assert_eq!(Duration::MAX, delta_b);
+}