Re: [PATCH v6 1/3] rust: configfs: introduce rust support for configfs

From: Andreas Hindborg
Date: Thu May 01 2025 - 14:12:08 EST


"Miguel Ojeda" <miguel.ojeda.sandonis@xxxxxxxxx> writes:

> On Thu, May 1, 2025 at 1:32 PM Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
>>
>> The one just before the cut?
>
> Both.

But why does that matter? Anything in the commit message after the cut
is dropped when applying the patch, right?

>
>> Thanks. Would be nice with a lint for missed intra-doc links.
>
> Definitely -- I filled it a while back:
>
> https://github.com/rust-lang/rust/issues/131510
>
>> Clippy gets mad if we move it up. Because rustfmt wants the unsafe block
>> to a new line:
>
> Yeah, then it is one of the cases I was referring to. In that case, it
> is fine, but please indent the safety comment to match the `unsafe`
> block.

OK. rustfmt does not seem to care about this though.

>
>> The reason I choose build_error is that if this should somehow end up
>> being evaluated in non-const context at some point, I want the build to
>> fail if the condition is not true. I don't think I get that with assert?
>
> I am not sure what you mean. My understanding is that `const` blocks,
> if execution reaches them, are always evaluated at compile-time (they
> are a const context):
>
> https://doc.rust-lang.org/reference/expressions/block-expr.html#const-blocks
>
> e.g.
>
> https://godbolt.org/z/h36s3nqWK
>
> We are lucky to have Gary with us, since he stabilized this particular
> language feature, so he can correct us! :)

I might not have the full picture, but it is my understanding that
while `const fn` are evaluated in const context when called from const
context, they _may_ be called from non-const context, and then they are
evaluated in non-const context if their arguments are not const [1].
They are not guaranteed to be evaluated in const context.

So my thinking is that down the road, refactoring of this code may cause
the `AttributeList::add` to be called in a way so that it is not
evaluated in const context, and then the `assert` would be evaluated at
run time. With `build_error` we would get an error during build.

But I should probably use `build_assert` instead of the conditional with
`build_error`.


Best regards,
Andreas Hindborg


[1] https://doc.rust-lang.org/reference/const_eval.html#r-const-eval.const-expr.list