Linux Documentation
 help / color / mirror / Atom feed
* [PATCH v1] docs: rust: mention #[track_caller] for functions that panic
@ 2026-11-18 23:44 FUJITA Tomonori
  2026-11-19  2:26 ` Gary Guo
  0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread

* Re: [PATCH v1] docs: rust: mention #[track_caller] for functions that panic
  2026-11-18 23:44 [PATCH v1] docs: rust: mention #[track_caller] for functions that panic FUJITA Tomonori
@ 2026-11-19  2:26 ` Gary Guo
  0 siblings, 0 replies; 2+ messages in thread
From: Gary Guo @ 2026-11-19  2:26 UTC (permalink / raw)
  To: FUJITA Tomonori, 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

On Wed Nov 18, 2026 at 11:44 PM GMT, FUJITA Tomonori wrote:
> 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].

I don't think this is a universal rule. `#[track_caller]` has a code and it
shouldn't be used unless you really care about the caller (or have the panicking
code being always inlined)

Best,
Gary


>
> 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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19  2:26 UTC | newest]

Thread overview: 2+ messages (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
2026-11-19  2:26 ` Gary Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox