rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
To: Timur Tabi <ttabi@nvidia.com>
Cc: "ojeda@kernel.org" <ojeda@kernel.org>,
	"aliceryhl@google.com" <aliceryhl@google.com>,
	 "lossin@kernel.org" <lossin@kernel.org>,
	"dakr@kernel.org" <dakr@kernel.org>,
	 "rust-for-linux@vger.kernel.org"
	<rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH] [v2] rust: introduce sfile macro for succinct code tracing
Date: Sat, 7 Jun 2025 12:17:10 +0200	[thread overview]
Message-ID: <CANiq72mWq5x2zr8CKXw3mchPMhy0gxHAd8cmCwe0bfaRBW03Og@mail.gmail.com> (raw)
In-Reply-To: <ecc4bb6c582bb99c17b4795d80d2556e98e590f9.camel@nvidia.com>

On Sat, Jun 7, 2025 at 12:11 AM Timur Tabi <ttabi@nvidia.com> wrote:
>
> I don't understand why, when I use "&FILE[start..]", this compiles as inline:
>
>         pr_err!("{}:{}\n", sfile!(), line!());
>
> but this doesn't:
>
>         const SFILE: &'static str = sfile!();
>
> It seems to me that the second line is "more const" than the first line, if that makes any sense.

The second call is in a const context, the first is just a normal
line. So the second must be a constant expression, which is a big
restriction on what you can write there, but the first doesn't require
that.

Hmm... Perhaps you are thinking that the compiler (or optimizer)
should know that it all resolves to a constant, and thus it should
allow it anyway.

However, constant evaluation doesn't work like that, i.e. even if some
expressions may happen to be able to be evaluated at compile-time, it
doesn't make them constant expressions.

It is similar to how C++'s `constexpr` works, if you have done that.
The languages keep expanding what can be done within const contexts
over time, but it is not based on whether a given instance could be.

(One place where we do use "this particular case must be X" kind of
logic is `build_assert!`).

> You mean you don't like [PATCH][V2]?  I've been doing that for 20 years, and this is the first time
> anyone's complained.

Sorry, I should have said "ideally" there too, since I intended it
mostly as a suggestion like the one in parenthesis. Neither of those
are blockers, of course, and we regularly take different styles of
patches. The `--base` thing is more "important" (useful).

Cheers,
Miguel

  parent reply	other threads:[~2025-06-07 10:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-03 19:54 [PATCH] [v2] rust: introduce sfile macro for succinct code tracing Timur Tabi
2025-06-03 22:53 ` Miguel Ojeda
2025-06-06 22:11   ` Timur Tabi
2025-06-07  0:13     ` John Hubbard
2025-06-07 10:17     ` Miguel Ojeda [this message]
2025-06-04  9:00 ` Alice Ryhl
2025-06-04 20:43   ` Timur Tabi

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=CANiq72mWq5x2zr8CKXw3mchPMhy0gxHAd8cmCwe0bfaRBW03Og@mail.gmail.com \
    --to=miguel.ojeda.sandonis@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=dakr@kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=ttabi@nvidia.com \
    /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;
as well as URLs for NNTP newsgroup(s).