From: FUJITA Tomonori <tomo@flapping.org>
To: corbet@lwn.net, ojeda@kernel.org
Cc: a.hindborg@kernel.org, acourbot@nvidia.com, aliceryhl@google.com,
bjorn3_gh@protonmail.com, boqun@kernel.org, dakr@kernel.org,
daniel.almeida@collabora.com, gary@garyguo.net,
lossin@kernel.org, rdunlap@infradead.org,
skhan@linuxfoundation.org, tamird@kernel.org, tmgross@umich.edu,
work@onurozkan.dev, linux-doc@vger.kernel.org,
rust-for-linux@vger.kernel.org,
FUJITA Tomonori <fujita.tomonori@gmail.com>
Subject: [PATCH v1] docs: rust: mention #[track_caller] for functions that panic
Date: Thu, 19 Nov 2026 08:44:51 +0900 [thread overview]
Message-ID: <20261118234452.2621985-1-tomo@flapping.org> (raw)
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
next reply other threads:[~2026-11-18 23:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 23:44 FUJITA Tomonori [this message]
2026-11-19 2:26 ` [PATCH v1] docs: rust: mention #[track_caller] for functions that panic Gary Guo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118234452.2621985-1-tomo@flapping.org \
--to=tomo@flapping.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-doc@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox