Re: [PATCH 06/12] rust: pin-init: rewrite `#[pin_data]` using `syn`

From: Gary Guo

Date: Sat Jan 10 2026 - 14:19:01 EST


On Sat Jan 10, 2026 at 4:41 PM GMT, Benno Lossin wrote:
> On Fri Jan 9, 2026 at 5:46 PM CET, Gary Guo wrote:
>> On Fri Jan 9, 2026 at 4:39 PM GMT, Benno Lossin wrote:
>>> On Fri Jan 9, 2026 at 1:47 PM CET, Gary Guo wrote:
>>>> On Thu Jan 8, 2026 at 1:50 PM GMT, Benno Lossin wrote:
>>>>> +fn strip_pin_annotations(struct_: &mut syn::ItemStruct) {
>>>>> + for field in &mut struct_.fields {
>>>>> + field.attrs.retain(|a| !a.path().is_ident("pin"));
>>>>> + }
>>>>> +}
>>>>
>>>> Multiple places have similar things for stripping annotations and checking if
>>>> structurally pinned. Would it make sense to do this at the very beginning, and
>>>> build a `HashSet` of structurally pinned fields, and use that as canonical
>>>> source for all generate_ functions?
>>>
>>> There is https://github.com/Rust-for-Linux/pin-init/pull/94, and I don't
>>> want to take away their work. I'll contact them and see if we can fold
>>> it into this commit/series.
>>
>> I don't think that's the same? I am proposing remove `#[pin]` and build a set at
>> the very beginning of `fn pin_data` and just use that set. Which is not what the
>> reference PR does.
>
> Oh yeah you're right. But `Field` doesn't implement `Hash`, so we sadly
> can't create a set of pinned fields. I'll just create a Vec with a bool
> and pass that around.

I was imagining just using `Ident` but I guess `cfg` is part of that too... Or
maybe just use numeric index inside `struct_.fields`.

Best,
Gary