[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DDXUPAELH6C2.3JK5JVGP87V8N@nvidia.com>
Date: Sun, 02 Nov 2025 11:25:03 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Miguel Ojeda" <miguel.ojeda.sandonis@...il.com>, "Alexandre Courbot"
<acourbot@...dia.com>
Cc: "Miguel Ojeda" <ojeda@...nel.org>, "Boqun Feng" <boqun.feng@...il.com>,
"Gary Guo" <gary@...yguo.net>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>, "Benno Lossin" <lossin@...nel.org>, "Andreas
Hindborg" <a.hindborg@...nel.org>, "Alice Ryhl" <aliceryhl@...gle.com>,
"Trevor Gross" <tmgross@...ch.edu>, "Danilo Krummrich" <dakr@...nel.org>,
"Nathan Chancellor" <nathan@...nel.org>, "Nicolas Schier"
<nicolas.schier@...ux.dev>, <linux-kernel@...r.kernel.org>,
<rust-for-linux@...r.kernel.org>, <linux-kbuild@...r.kernel.org>
Subject: Re: [PATCH RESEND] rust: enable slice_flatten feature and abstract
it through an extension trait
On Sun Nov 2, 2025 at 12:36 AM JST, Miguel Ojeda wrote:
> On Sat, Nov 1, 2025 at 2:32 PM Alexandre Courbot <acourbot@...dia.com> wrote:
>>
>> Hopefully it captures Miguel's suggestion [2] accurately, but please let
>> me know if I missed something.
>
> Yeah, this is what I meant and looks great -- thanks!
>
> If you need to use it this cycle in another branch:
>
> Acked-by: Miguel Ojeda <ojeda@...nel.org>
>
> Otherwise, I will pick it up.
Thanks!
>
>> +config RUSTC_HAS_SLICE_AS_FLATTENED
>
> I guess you used this one since they renamed it and since we don't use
> the `alloc` method. It is fine, both options are confusing in
> different ways, but sometimes the feature name is the only one that
> can be used (since it may enable several methods etc.), so I wonder if
> we should try to use that consistently.
Ah, I think I see what you mean. The `slice_flatten` feature has been
removed in 1.80 with the stabilization and method rename, so I guess we
would have to do something like:
config RUSTC_HAS_SLICE_FLATTEN
def_bool RUSTC_VERSION < 108000
... and invert the logic in the code. That would run contrary to the
other `RUSTC_HAS` options requiring at least a given version though.
Also not all of these seem to be tied to a feature;
`RUSTC_HAS_FILE_AS_C_STR` appears to refer to the
`Location::file_as_c_str` method, which is behind the `file_with_nul`
feature.
So I guess `config RUST_HAS_AS_FLATTENED` would also work. I'm happy to
follow what you think is best here. :)
>
>> +/// In Rust 1.80, the previously unstable `slice::flatten` family of methods
>> +/// have been stabilized and renamed from `flatten` to `as_flattened`.
>> +///
>> +/// This creates an issue for as long as the MSRV is < 1.80, as the same functionality is provided
>> +/// by different methods depending on the compiler version.
>> +///
>> +/// This extension trait solves this by abstracting `as_flatten` and calling the correct method
>> +/// depending on the Rust version.
>> +///
>> +/// This trait can be removed once the MSRV passes 1.80.
>
> These paragraphs sound like implementations details -- I would
> probably leave that to the commit message or normal comments instead
> (we should notice we need to remove these thanks to the line in
> `Kconfig` already).
>
> Nit: two spaces above.
>
>> + /// Takes an `&[[T; N]]` and flattens it to a `&[T]`.
>
> Nit: I don't know how one is supposed to pronounce these, but I guess
> it is "a" in the first one, like the second one (the upstream docs
> also do that).
The funny thing is that I intented to copy the Rust doc for
`as_flattened`, but failed to even copy/paste it properly! ^_^; Fixed,
thanks.
Powered by blists - more mailing lists