Skip to content

Commit d56b1fd

Browse files
committed
Make duration_since use checked_duration_since
1 parent 37cfeb2 commit d56b1fd

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/libstd/time.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl Instant {
212212
/// ```
213213
#[stable(feature = "time2", since = "1.8.0")]
214214
pub fn duration_since(&self, earlier: Instant) -> Duration {
215-
self.0.sub_instant(&earlier.0)
215+
self.0.checked_sub_instant(&earlier.0).expect("supplied instant is later than self")
216216
}
217217

218218
/// Returns the amount of time elapsed from another instant to this one,
@@ -233,11 +233,7 @@ impl Instant {
233233
/// ```
234234
#[unstable(feature = "checked_duration_since", issue = "58402")]
235235
pub fn checked_duration_since(&self, earlier: Instant) -> Option<Duration> {
236-
if self >= &earlier {
237-
Some(self.0.sub_instant(&earlier.0))
238-
} else {
239-
None
240-
}
236+
self.0.checked_sub_instant(&earlier.0)
241237
}
242238

243239
/// Returns the amount of time elapsed from another instant to this one,

0 commit comments

Comments
 (0)