* [PATCH v1] docs: rust: mention #[track_caller] for functions that panic
@ 2026-11-18 23:44 FUJITA Tomonori
0 siblings, 0 replies; only message in thread
From: FUJITA Tomonori @ 2026-11-18 23:44 UTC (permalink / raw)
To: corbet, ojeda
Cc: a.hindborg, acourbot, aliceryhl, bjorn3_gh, boqun, dakr,
daniel.almeida, gary, lossin, rdunlap, skhan, tamird, tmgross,
work, linux-doc, rust-for-linux, FUJITA Tomonori
From: FUJITA Tomonori <fujita.tomonori@gmail.com>
When a function panics, the panic message shows a line inside the
function, not the caller. Adding #[track_caller] makes the message show
the caller's location.
Add a sentence to the "# Panics" guideline: a function that may panic
should also be marked with #[track_caller].
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
Documentation/rust/coding-guidelines.rst | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Documentation/rust/coding-guidelines.rst b/Documentation/rust/coding-guidelines.rst
index 3198be3a6d63..c7404ea7ba13 100644
--- a/Documentation/rust/coding-guidelines.rst
+++ b/Documentation/rust/coding-guidelines.rst
@@ -241,6 +241,10 @@ in the kernel:
- While not shown here, if a function may panic, the conditions under which
that happens must be described under a ``# Panics`` section.
+ Such a function should also be marked with ``#[track_caller]``, so that
+ the panic message shows the location of the caller instead of a line
+ inside the function.
+
Please note that panicking should be very rare and used only with a good
reason. In almost all cases, a fallible approach should be used, typically
returning a ``Result``.
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-18 23:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 23:44 [PATCH v1] docs: rust: mention #[track_caller] for functions that panic FUJITA Tomonori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox