[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <D91B4P0WDM7B.3IKSOWUAGEBFK@nvidia.com>
Date: Tue, 08 Apr 2025 22:55:36 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Alice Ryhl" <aliceryhl@...gle.com>
Cc: "Miguel Ojeda" <miguel.ojeda.sandonis@...il.com>, "Benno Lossin"
<benno.lossin@...ton.me>, "Danilo Krummrich" <dakr@...nel.org>, "Miguel
Ojeda" <ojeda@...nel.org>, "Alex Gaynor" <alex.gaynor@...il.com>, "Boqun
Feng" <boqun.feng@...il.com>, "Gary Guo" <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Andreas
Hindborg" <a.hindborg@...nel.org>, "Trevor Gross" <tmgross@...ch.edu>,
<rust-for-linux@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] rust: alloc: allow coercion from `Box<T>` to `Box<dyn
U>` if T implements U
On Tue Apr 8, 2025 at 10:40 PM JST, Alice Ryhl wrote:
> On Tue, Apr 8, 2025 at 3:19 PM Alexandre Courbot <acourbot@...dia.com> wrote:
>>
>> On Tue Apr 8, 2025 at 7:35 PM JST, Miguel Ojeda wrote:
>> > On Tue, Apr 8, 2025 at 12:22 PM Benno Lossin <benno.lossin@...ton.me> wrote:
>> >>
>> >> You forgot to add the `A: Allocator` generic here and in the impl below.
>> >
>> > Yeah, for this sort of changes (ideally, all patches, really), please
>> > test with both the minimum supported version and the latest.
>>
>> Apologies for that, I had no idea how to build using a specific
>> toolchain and did the wrong thing, which is sending without proper
>> testing.
>>
>> I had some trouble finding how to 1) find out the minimum supported Rust
>> version, and 2) how to build using a specific toolchain.
>>
>> For 1) I eventually found a hardcoded version in
>> scripts/min-tool-version.sh ; and 2) is somehow documentated in the
>> Quick Start guide that mentions the `rustup override set stable`
>> command.
>>
>> I can send a patch against the Coding Guidelines adding a section to
>> encourage testing against the minimum version and explain how to force a
>> specific Rust version if you can confirm this would be helpful (and that
>> min-tool-version.sh is the correct way to check the minimum supported
>> Rust version).
>>
>> >
>> > For instance, there is another issue, `#[pointee]` is only applicable
>> > when you have the feature:
>> >
>> > error: cannot find attribute `pointee` in this scope
>> > --> rust/kernel/alloc/kbox.rs:66:18
>> > |
>> > 66 | pub struct Box<#[pointee] T: ?Sized, A:
>> > Allocator>(NonNull<T>, PhantomData<A>);
>>
>> Mmm that one is trickier to address - I don't know of a way to make this
>> `#[pointee]` attribute depedent on `CONFIG_RUSTC_HAS_COERCE_POINTEE`...
>> Only solution I see if having two separate declarations for `Box`, and
>> then we have the problem of bindings the rustdoc to the declaration that
>> is picked at build time... Any idea for how to best address this?
>
> This might work:
> struct Box<#[cfg_attr(CONFIG_RUSTC_HAS_COERCE_POINTEE, pointee)] T>
I thought I'd tried that already and it failed, but giving it another go
now, it indeed *does* work. I must have been thrown off by a different
build error at that time. This solves everything then - thanks a lot!
Powered by blists - more mailing lists