]> git.lizzy.rs Git - rust.git/commitdiff
Fix confusing error message for sub_instant
authorClaudio Bley <claudio.bley@gmail.com>
Thu, 31 May 2018 20:05:36 +0000 (22:05 +0200)
committerGitHub <noreply@github.com>
Thu, 31 May 2018 20:05:36 +0000 (22:05 +0200)
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
```

src/libstd/sys/unix/time.rs

index 83127935909931211957d8df0e34e7c599e92ceb..f7459cb55d5ca7d0f870d7ca2e78cf61f345b875 100644 (file)
@@ -289,7 +289,7 @@ pub fn now() -> Instant {
 
         pub fn sub_instant(&self, other: &Instant) -> Duration {
             self.t.sub_timespec(&other.t).unwrap_or_else(|_| {
-                panic!("other was less than the current instant")
+                panic!("other was greater than the current instant")
             })
         }