Skip to content

Commit

Permalink
Add documentation about panicking Add<Duration> impls
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Dec 14, 2018
1 parent 018f8a0 commit 496f547
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/libstd/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ impl Instant {
impl Add<Duration> for Instant {
type Output = Instant;

/// # Panics
///
/// This function may panic if the resulting point in time cannot be represented by the
/// underlying data structure. See [`checked_add`] for a version without panic.
///
/// [`checked_add`]: ../../std/time/struct.Instant.html#method.checked_add
fn add(self, other: Duration) -> Instant {
self.checked_add(other)
.expect("overflow when adding duration to instant")
Expand Down Expand Up @@ -397,6 +403,12 @@ impl SystemTime {
impl Add<Duration> for SystemTime {
type Output = SystemTime;

/// # Panics
///
/// This function may panic if the resulting point in time cannot be represented by the
/// underlying data structure. See [`checked_add`] for a version without panic.
///
/// [`checked_add`]: ../../std/time/struct.SystemTime.html#method.checked_add
fn add(self, dur: Duration) -> SystemTime {
self.checked_add(dur)
.expect("overflow when adding duration to instant")
Expand Down

0 comments on commit 496f547

Please sign in to comment.