Skip to content

Commit 4415d07

Browse files
matthiaskrgrgitbot
authored and
gitbot
committed
Rollup merge of rust-lang#137207 - petertodd:2025-add-track-caller-to-duration-div, r=jhpratt
Add #[track_caller] to Duration Div impl Previously the location of the divide-by-zero error condition would be attributed to the code in the rust standard library, eg: thread 'main' panicked at /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/time.rs:1172:31: divide by zero error when dividing duration by scalar With #[track_caller] the error is correctly attributed to the callee.
2 parents 1a4ad2c + 25dc446 commit 4415d07

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

core/src/time.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ impl Div<u32> for Duration {
11681168
type Output = Duration;
11691169

11701170
#[inline]
1171+
#[track_caller]
11711172
fn div(self, rhs: u32) -> Duration {
11721173
self.checked_div(rhs).expect("divide by zero error when dividing duration by scalar")
11731174
}
@@ -1176,6 +1177,7 @@ impl Div<u32> for Duration {
11761177
#[stable(feature = "time_augmented_assignment", since = "1.9.0")]
11771178
impl DivAssign<u32> for Duration {
11781179
#[inline]
1180+
#[track_caller]
11791181
fn div_assign(&mut self, rhs: u32) {
11801182
*self = *self / rhs;
11811183
}

0 commit comments

Comments
 (0)