Skip to content

Commit

Permalink
Add missing inline attributes to Duration trait impls
Browse files Browse the repository at this point in the history
  • Loading branch information
elichai authored Oct 3, 2023
1 parent e3c631b commit ebc2923
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ impl Duration {
impl Add for Duration {
type Output = Duration;

#[inline]
fn add(self, rhs: Duration) -> Duration {
self.checked_add(rhs).expect("overflow when adding durations")
}
Expand All @@ -918,6 +919,7 @@ impl Add for Duration {
#[stable(feature = "time_augmented_assignment", since = "1.9.0")]
impl AddAssign for Duration {
fn add_assign(&mut self, rhs: Duration) {
#[inline]
*self = *self + rhs;
}
}
Expand All @@ -926,13 +928,15 @@ impl AddAssign for Duration {
impl Sub for Duration {
type Output = Duration;

#[inline]
fn sub(self, rhs: Duration) -> Duration {
self.checked_sub(rhs).expect("overflow when subtracting durations")
}
}

#[stable(feature = "time_augmented_assignment", since = "1.9.0")]
impl SubAssign for Duration {
#[inline]
fn sub_assign(&mut self, rhs: Duration) {
*self = *self - rhs;
}
Expand All @@ -942,6 +946,7 @@ impl SubAssign for Duration {
impl Mul<u32> for Duration {
type Output = Duration;

#[inline]
fn mul(self, rhs: u32) -> Duration {
self.checked_mul(rhs).expect("overflow when multiplying duration by scalar")
}
Expand All @@ -951,13 +956,15 @@ impl Mul<u32> for Duration {
impl Mul<Duration> for u32 {
type Output = Duration;

#[inline]
fn mul(self, rhs: Duration) -> Duration {
rhs * self
}
}

#[stable(feature = "time_augmented_assignment", since = "1.9.0")]
impl MulAssign<u32> for Duration {
#[inline]
fn mul_assign(&mut self, rhs: u32) {
*self = *self * rhs;
}
Expand All @@ -967,13 +974,15 @@ impl MulAssign<u32> for Duration {
impl Div<u32> for Duration {
type Output = Duration;

#[inline]
fn div(self, rhs: u32) -> Duration {
self.checked_div(rhs).expect("divide by zero error when dividing duration by scalar")
}
}

#[stable(feature = "time_augmented_assignment", since = "1.9.0")]
impl DivAssign<u32> for Duration {
#[inline]
fn div_assign(&mut self, rhs: u32) {
*self = *self / rhs;
}
Expand Down

0 comments on commit ebc2923

Please sign in to comment.