Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing inline attributes to Duration trait impls #116386

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,13 +910,15 @@ 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")
}
}

#[stable(feature = "time_augmented_assignment", since = "1.9.0")]
impl AddAssign for Duration {
#[inline]
fn add_assign(&mut self, rhs: Duration) {
*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