Skip to content

Commit 753e8f3

Browse files
Rollup merge of rust-lang#51255 - avdv:patch-1, r=kennytm
Fix confusing error message for sub_instant When subtracting an Instant from another, the function will panick when `RHS > self`, but the error message confusingly displays a different error: ```rust let i = Instant::now(); let other = Instant::now(); if other > i { println!("{:?}", i - other); } ``` This results in a panic: ``` thread 'test_instant' panicked at 'other was less than the current instant', libstd/sys/unix/time.rs:292:17 ``` But clearly, `other` was actually greater than the current instant.
2 parents 1225faf + 33c4b37 commit 753e8f3

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/libstd/sys/redox/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl Instant {
144144

145145
pub fn sub_instant(&self, other: &Instant) -> Duration {
146146
self.t.sub_timespec(&other.t).unwrap_or_else(|_| {
147-
panic!("other was less than the current instant")
147+
panic!("specified instant was later than self")
148148
})
149149
}
150150

src/libstd/sys/unix/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ mod inner {
289289

290290
pub fn sub_instant(&self, other: &Instant) -> Duration {
291291
self.t.sub_timespec(&other.t).unwrap_or_else(|_| {
292-
panic!("other was less than the current instant")
292+
panic!("specified instant was later than self")
293293
})
294294
}
295295

0 commit comments

Comments
 (0)