about summary refs log tree commit diff
path: root/library/std/tests/time.rs
diff options
context:
space:
mode:
authorLaurențiu Nicola <lnicola@users.noreply.github.com>2025-09-29 04:29:28 +0000
committerGitHub <noreply@github.com>2025-09-29 04:29:28 +0000
commit930451e17d47cc27b6c96cb358dfae2ed3a97c67 (patch)
tree722e3fdf88fdae0903cd1ff43cfc801db18345d3 /library/std/tests/time.rs
parentc0e45c896823664c49d631e961208d640dc43c58 (diff)
parent24f6f94c5ad90be5d1ced24d83b8485712bcc27a (diff)
downloadrust-930451e17d47cc27b6c96cb358dfae2ed3a97c67.tar.gz
rust-930451e17d47cc27b6c96cb358dfae2ed3a97c67.zip
Merge pull request #20761 from rust-lang/rustc-pull
Rustc pull update
Diffstat (limited to 'library/std/tests/time.rs')
-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);
+}