Re: [PATCH v2 1/7] rust: build_assert: add instructions for use with function arguments

From: John Hubbard

Date: Mon Dec 01 2025 - 20:38:51 EST


On 12/1/25 3:06 PM, Miguel Ojeda wrote:
> On Mon, Dec 1, 2025 at 8:31 PM John Hubbard <jhubbard@xxxxxxxxxx> wrote:
>>
>> Mainly just: is there a way to automatically "derive" (generate) an
>> always-inline directive for any function that attempts to call
>> build_assert!() on any of its arguments? And in fact, *force* the
>> always-inline, if it is not forced hard enough today.
>>
>> Something along those lines.
>
> "Wide-scoped" macros can do passes like that, i.e. like some projects
> do to add extra syntax everywhere. Not sure we want to get into that
> world, though.
>
> Instead, if we are just talking about checking, then I think we could
> have an attribute macro to mark such functions, and then
> `build_assert!` could fail "by default" unless inside one of those,
> and it would get rewritten into the proper form by the macro, so any
> call without it would fail. It is always nice to mark special
> functions anyway, just like our `export` one.
>
> Otherwise, for more than just checking, I guess a custom tool like
> Klint could also do it for us (I am sure Gary has ideas here).
>
>> I will bring this up (along with the KSYM_NAME_LEN hashed symbol project)
>> to our internal Rust groups. Both of these seem like nice, self-contained
>> projects that someone could really get into.
>
> That is great -- thanks!

For the build_assert!() project, I didn't even get that far, because it
turns out that Joel Fernandes (+Cc) is already working hard on this.

>
> On related news, Antoni (Cc'd) told me yesterday that he noticed
> `inline(always)` was needed when using the GCC backend too, so this
> series will help him too.
>
> Cheers,
> Miguel


thanks,
--
John Hubbard