diff options
| author | Stepan Koltsov <stepan.koltsov@gmail.com> | 2025-09-24 20:32:50 +0100 |
|---|---|---|
| committer | Stepan Koltsov <stepan.koltsov@gmail.com> | 2025-09-24 21:07:26 +0100 |
| commit | 92859e98ee1a2101df8322a8581e4d638eb15078 (patch) | |
| tree | 8f86a2f4a44504ca920b5a3116ea001a17b5c98a /library/std/tests | |
| parent | 15283f6fe95e5b604273d13a428bab5fc0788f5a (diff) | |
| download | rust-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.rs | 16 |
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); +} |
