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

From: Miguel Ojeda
Date: Sat May 03 2025 - 07:19:05 EST


On Fri, May 2, 2025 at 8:57 AM Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
>
> Right, they are not from const context, but they are inside a `let`
> statement, so if all the captured variables are constant (which they
> are), the let statement will be evaluated in const context [1], right?

No, I don't think so. Though I don't know what you mean by "captured
variables" here or why you point to [const-eval.const-context.init].

The way I read the reference is that Rust only guarantees evaluation
at compile-time within const contexts, and a `let` statement is not a
const context and its initializer is not one of the ones listed in
[const-eval.const-context.init]. `const fn` isn't a const context
either.

Which makes sense -- the `let` initializers are just "normal"
expressions, i.e. you don't want to limit the kinds of code you can
run there.

For instance, here there is a panic at runtime trying to mimic a bit the patch:

https://godbolt.org/z/v5qdK9vve

Similarly, if I take your patch and put there an `assert!(false)` in
`add` -- I see no build error and `objdump` shows the panic call from
the sample.

Cheers,
Miguel