Skip to content

Commit 4910642

Browse files
committed
Auto merge of rust-lang#116386 - elichai:patch-2, r=thomcc
Add missing inline attributes to Duration trait impls Currently `Duration::checked_add` is marked `#[inline]` but it's trait relative `Add::add` is not. Leading to a case where: ```rust pub fn foo() -> Duration { Duration::from_secs(10) + Duration::from_millis(6) } pub fn bar() -> Duration { Duration::from_secs(10).checked_add(Duration::from_millis(6)).expect("overflow when adding durations") } ``` compiles to: ```asm playground::foo: movl $10, %edi xorl %esi, %esi xorl %edx, %edx movl $6000000, %ecx jmpq *<core::time::Duration as core::ops::arith::Add>::add@GOTPCREL(%rip) playground::bar: movl $10, %eax movl $6000000, %edx retq ``` (The same happens for all arithmetic operation)
2 parents 79f38b7 + 92c9bcd commit 4910642

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

library/core/src/time.rs

+9
Original file line numberDiff line numberDiff line change
@@ -910,13 +910,15 @@ impl Duration {
910910
impl Add for Duration {
911911
type Output = Duration;
912912

913+
#[inline]
913914
fn add(self, rhs: Duration) -> Duration {
914915
self.checked_add(rhs).expect("overflow when adding durations")
915916
}
916917
}
917918

918919
#[stable(feature = "time_augmented_assignment", since = "1.9.0")]
919920
impl AddAssign for Duration {
921+
#[inline]
920922
fn add_assign(&mut self, rhs: Duration) {
921923
*self = *self + rhs;
922924
}
@@ -926,13 +928,15 @@ impl AddAssign for Duration {
926928
impl Sub for Duration {
927929
type Output = Duration;
928930

931+
#[inline]
929932
fn sub(self, rhs: Duration) -> Duration {
930933
self.checked_sub(rhs).expect("overflow when subtracting durations")
931934
}
932935
}
933936

934937
#[stable(feature = "time_augmented_assignment", since = "1.9.0")]
935938
impl SubAssign for Duration {
939+
#[inline]
936940
fn sub_assign(&mut self, rhs: Duration) {
937941
*self = *self - rhs;
938942
}
@@ -942,6 +946,7 @@ impl SubAssign for Duration {
942946
impl Mul<u32> for Duration {
943947
type Output = Duration;
944948

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

959+
#[inline]
954960
fn mul(self, rhs: Duration) -> Duration {
955961
rhs * self
956962
}
957963
}
958964

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

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

975983
#[stable(feature = "time_augmented_assignment", since = "1.9.0")]
976984
impl DivAssign<u32> for Duration {
985+
#[inline]
977986
fn div_assign(&mut self, rhs: u32) {
978987
*self = *self / rhs;
979988
}

0 commit comments

Comments
 (0)