From: "Gary Guo" <gary@garyguo.net>
To: "Eliot Courtney" <ecourtney@nvidia.com>,
"Gary Guo" <gary@garyguo.net>,
"Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v2 0/3] rust: const_eval: add a mechanism to do const trait calls
Date: Wed, 09 Sep 2026 15:32:38 +0100 [thread overview]
Message-ID: <DLAUXSH2302V.2OKAZYA7XOEEF@garyguo.net> (raw)
In-Reply-To: <DL8Z2OZLK8KS.1KVH6W27ZTOWG@nvidia.com>
On Mon Sep 7, 2026 at 10:21 AM BST, Eliot Courtney wrote:
> On Fri Sep 4, 2026 at 12:46 AM JST, Gary Guo wrote:
>> On Thu Sep 3, 2026 at 4:34 PM BST, Miguel Ojeda wrote:
>>> On Thu, Sep 3, 2026 at 5:21 PM Gary Guo <gary@garyguo.net> wrote:
>>>>
>>>> Add a mechanism to perform const trait method calls, with the same type
>>>> inference capabilities. This would only work for concrete types (not inside
>>>> generic functions).
>>>>
>>>> As an example, convert `as_char_ptr_in_const_context`, so instead of
>>>>
>>>> kernel::str::as_char_ptr_in_const_context(c_str)
>>>>
>>>> one may write
>>>>
>>>> const_call!(c_str.as_char_ptr())
>>>>
>>>> instead.
>>>>
>>>> Signed-off-by: Gary Guo <gary@garyguo.net>
>>>
>>> Thanks for resending this!
>>>
>>> So I definitely like having `#[const_eval_only]`, because we do want
>>> to limit those calls sometimes and it is nice to have C++'s equivalent
>>> to `consteval` (perhaps this could be called just `#[consteval]` to
>>> match?); i.e. what we talked about in the call.
I'm okay with either. I put in `_only` because I think it makes it very clear
that this is not just const-evalutable (that's provided by `const`) and is
*always* const evaled.
>>>
>>> On `Const` and `const_call!`, i.e. the other two patches: I am not
>>> sure if we care that much to introduce a macro for it, but it doesn't
>>> look bad either. I guess perhaps it helps to have a consistent way to
>>> do it and to easily remove it later when the actual feature lands in
>>> Rust. I would like to hear some thoughts on it from others.
>>
>> I think it's good to have such macro compared to our current approach; it can be
>> made into a identity macro once we have const trait impl.
>>
>> FWIW, I even considered an extra macro that allow you to write
>>
>> #[const_trait_impl] // #[const_trait_impl(foreign)] for core types
>> impl MyTrait for MyType {}
>>
>> and generate the `impl Const` part too (and also add a line to the documentation
>> that the method is const-callable with `const_call!()`).
>>
>> Best,
>> Gary
>
> I agree with the consteval macro, that sounds very nice.
>
> On the const_call! I have similar thoughts to Miguel. I reckon if we
> have a bunch of prospective users of this right now, and some thoughts
> on what would use this in the future then it's good. If it's just one
> use case right now, then not so sure.
Some other candidates include `Alignable` (we currently have a "const_align_up")
and maybe `IntoSafeCast`.
Best,
Gary
prev parent reply other threads:[~2026-09-09 14:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 15:21 [PATCH v2 0/3] rust: const_eval: add a mechanism to do const trait calls Gary Guo
2026-09-03 15:21 ` [PATCH v2 1/3] rust: const_eval: add `#[const_eval_only]` attribute Gary Guo
2026-09-07 8:45 ` Eliot Courtney
2026-09-09 14:36 ` Gary Guo
2026-09-03 15:21 ` [PATCH v2 2/3] rust: const_eval: allow const trait method invocation in some contexts Gary Guo
2026-09-03 15:21 ` [PATCH v2 3/3] rust: str: convert `as_char_ptr` to work with `const_call!` Gary Guo
2026-09-03 15:34 ` [PATCH v2 0/3] rust: const_eval: add a mechanism to do const trait calls Miguel Ojeda
2026-09-03 15:46 ` Gary Guo
2026-09-07 9:21 ` Eliot Courtney
2026-09-09 14:32 ` 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=DLAUXSH2302V.2OKAZYA7XOEEF@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=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=ecourtney@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.