Skip to content

Commit f4cb666

Browse files
Rollup merge of #156133 - RalfJung:time-panic-track-caller, r=Mark-Simulacrum
mark some panicking methods around Duration as track_caller Currently when they panic it looks like this ``` 0.005045 ---- instant_checked_duration_since_nopanic stdout ---- 0.000039 0.000009 thread 'instant_checked_duration_since_nopanic' (2) panicked at /home/runner/work/miri-test-libstd/miri-test-libstd/rust-src-patched/library/std/src/time.rs:445:33: 0.000007 overflow when subtracting duration from instant 0.000006 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace 0.000007 note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect ``` That's pretty useless. Also fix the panic message while we are at it.
2 parents fb9735b + 09dc7fc commit f4cb666

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

library/std/src/time.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ impl Add<Duration> for Instant {
425425
///
426426
/// This function may panic if the resulting point in time cannot be represented by the
427427
/// underlying data structure. See [`Instant::checked_add`] for a version without panic.
428+
#[track_caller]
428429
fn add(self, other: Duration) -> Instant {
429430
self.checked_add(other).expect("overflow when adding duration to instant")
430431
}
@@ -441,6 +442,7 @@ impl AddAssign<Duration> for Instant {
441442
impl Sub<Duration> for Instant {
442443
type Output = Instant;
443444

445+
#[track_caller]
444446
fn sub(self, other: Duration) -> Instant {
445447
self.checked_sub(other).expect("overflow when subtracting duration from instant")
446448
}
@@ -742,8 +744,9 @@ impl Add<Duration> for SystemTime {
742744
///
743745
/// This function may panic if the resulting point in time cannot be represented by the
744746
/// underlying data structure. See [`SystemTime::checked_add`] for a version without panic.
747+
#[track_caller]
745748
fn add(self, dur: Duration) -> SystemTime {
746-
self.checked_add(dur).expect("overflow when adding duration to instant")
749+
self.checked_add(dur).expect("overflow when adding duration to `SystemTime`")
747750
}
748751
}
749752

@@ -758,8 +761,9 @@ impl AddAssign<Duration> for SystemTime {
758761
impl Sub<Duration> for SystemTime {
759762
type Output = SystemTime;
760763

764+
#[track_caller]
761765
fn sub(self, dur: Duration) -> SystemTime {
762-
self.checked_sub(dur).expect("overflow when subtracting duration from instant")
766+
self.checked_sub(dur).expect("overflow when subtracting duration from `SystemTime`")
763767
}
764768
}
765769

0 commit comments

Comments
 (0)