Skip to content

Commit 87b71c0

Browse files
committed
Repro duration_since regression from issue 146228
1 parent 52618eb commit 87b71c0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

library/std/tests/time.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,18 @@ fn big_math() {
227227
check(instant.checked_add(Duration::from_secs(100)), Instant::checked_sub);
228228
check(instant.checked_add(Duration::from_secs(i64::MAX as _)), Instant::checked_sub);
229229
}
230+
231+
#[test]
232+
#[cfg(unix)]
233+
fn system_time_duration_since_max_range_on_unix() {
234+
// Repro regression https://github.com/rust-lang/rust/issues/146228
235+
236+
// Min and max values of `SystemTime` on Unix.
237+
let min = SystemTime::UNIX_EPOCH - (Duration::new(i64::MAX as u64 + 1, 0));
238+
let max = SystemTime::UNIX_EPOCH + (Duration::new(i64::MAX as u64, 999_999_999));
239+
240+
// This should succeed and not return a SystemTimeError due to incorrect comparison overflow
241+
let delta = max.duration_since(min).expect("duration_since overflow");
242+
243+
assert_eq!(Duration::MAX, delta);
244+
}

0 commit comments

Comments
 (0)