Skip to contentSkip to conversation

rust: time: add #[track_caller] to Delta division and remainder

PATCH In review FUJITA Tomonori 2 participants 2 messages Nov 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: time: add #[track_caller] to Delta division and remainder

From: FUJITA Tomonori <[email protected]>

Delta's div() and rem_nanos() panic if the divisor is zero, or if i64::MIN is divided by -1. In these cases the caller passed a wrong value, but the panic message shows a line in time.rs.

Add #[track_caller] so that the panic message shows the caller's location instead.

---
 rust/kernel/time.rs | 2 ++
 1 file changed, 2 insertions(+)
rust/kernel/time.rs +2 -0
index aeb518b91e1c..493a4d0774e8 100644
@@ -512,6 +512,7 @@ impl ops::Div for Delta {
     ///
     /// Panics if `rhs` is zero, or if `self` represents [`i64::MIN`] nanoseconds
     /// and `rhs` represents `-1` nanosecond.
+    #[track_caller]
     #[inline]
     fn div(self, rhs: Self) -> Self::Output {
         if rhs.value == 0 {
@@ -725,6 +726,7 @@ pub fn to_jiffies_timeout(self) -> Delta<Jiffy> {
     ///
     /// Panics if `divisor` is zero, or if `self` represents [`i64::MIN`]
     /// nanoseconds and `divisor` is `-1`.
+    #[track_caller]
     #[inline]
     pub fn rem_nanos(self, divisor: i32) -> Self {
         if divisor == 0 {

base-commit: 6b391eec2ddeb3ab2681cc5dee16d29e00202438

Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · FUJITA Tomonori

From: FUJITA Tomonori <[email protected]>

Delta's div() and rem_nanos() panic if the divisor is zero, or if i64::MIN is divided by -1. In these cases the caller passed a wrong value, but the panic message shows a line in time.rs.

Add #[track_caller] so that the panic message shows the caller's location instead.