Linux Documentation
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "FUJITA Tomonori" <tomo@flapping.org>, <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: Re: [PATCH v1] docs: rust: mention #[track_caller] for functions that panic
Date: Thu, 19 Nov 2026 02:26:12 +0000	[thread overview]
Message-ID: <DMYTYA2G4WEM.3U76EBDBUEPN9@garyguo.net> (raw)
In-Reply-To: <20261118234452.2621985-1-tomo@flapping.org>

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



      reply	other threads:[~2026-11-19  2:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=DMYTYA2G4WEM.3U76EBDBUEPN9@garyguo.net \
    --to=gary@garyguo.net \
    --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=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=tomo@flapping.org \
    --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