Rollup merge of #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.
This commit is contained in:
@@ -144,7 +144,7 @@ impl Instant {
|
|||||||
|
|
||||||
pub fn sub_instant(&self, other: &Instant) -> Duration {
|
pub fn sub_instant(&self, other: &Instant) -> Duration {
|
||||||
self.t.sub_timespec(&other.t).unwrap_or_else(|_| {
|
self.t.sub_timespec(&other.t).unwrap_or_else(|_| {
|
||||||
panic!("other was less than the current instant")
|
panic!("specified instant was later than self")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ mod inner {
|
|||||||
|
|
||||||
pub fn sub_instant(&self, other: &Instant) -> Duration {
|
pub fn sub_instant(&self, other: &Instant) -> Duration {
|
||||||
self.t.sub_timespec(&other.t).unwrap_or_else(|_| {
|
self.t.sub_timespec(&other.t).unwrap_or_else(|_| {
|
||||||
panic!("other was less than the current instant")
|
panic!("specified instant was later than self")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user