[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DFK62LHP35VZ.2HKVXST2SEI39@kernel.org>
Date: Fri, 09 Jan 2026 16:34:15 +0100
From: "Benno Lossin" <lossin@...nel.org>
To: "Gary Guo" <gary@...yguo.net>, "Miguel Ojeda" <ojeda@...nel.org>, "Boqun
Feng" <boqun.feng@...il.com>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>, "Andreas Hindborg" <a.hindborg@...nel.org>,
"Alice Ryhl" <aliceryhl@...gle.com>, "Trevor Gross" <tmgross@...ch.edu>,
"Danilo Krummrich" <dakr@...nel.org>, "Fiona Behrens" <me@...enk.dev>,
"Tamir Duberstein" <tamird@...il.com>, "Alban Kurti" <kurti@...icto.ai>
Cc: <rust-for-linux@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 05/12] rust: pin-init: rewrite the `#[pinned_drop]`
attribute macro using `syn`
On Fri Jan 9, 2026 at 1:12 PM CET, Gary Guo wrote:
> On Thu Jan 8, 2026 at 1:50 PM GMT, Benno Lossin wrote:
>> diff --git a/rust/pin-init/internal/src/pinned_drop.rs b/rust/pin-init/internal/src/pinned_drop.rs
>> index cf8cd1c42984..4df2cb9959fb 100644
>> --- a/rust/pin-init/internal/src/pinned_drop.rs
>> +++ b/rust/pin-init/internal/src/pinned_drop.rs
>> @@ -1,49 +1,56 @@
>> // SPDX-License-Identifier: Apache-2.0 OR MIT
>>
>> -use proc_macro2::{TokenStream, TokenTree};
>> -use quote::quote;
>> +use proc_macro2::TokenStream;
>> +use quote::{quote, quote_spanned};
>> +use syn::{parse::Nothing, parse_quote, spanned::Spanned, ImplItem, ItemImpl, Token};
>>
>> -pub(crate) fn pinned_drop(_args: TokenStream, input: TokenStream) -> TokenStream {
>> - let mut toks = input.into_iter().collect::<Vec<_>>();
>> - assert!(!toks.is_empty());
>> - // Ensure that we have an `impl` item.
>> - assert!(matches!(&toks[0], TokenTree::Ident(i) if i == "impl"));
>> - // Ensure that we are implementing `PinnedDrop`.
>> - let mut nesting: usize = 0;
>> - let mut pinned_drop_idx = None;
>> - for (i, tt) in toks.iter().enumerate() {
>> - match tt {
>> - TokenTree::Punct(p) if p.as_char() == '<' => {
>> - nesting += 1;
>> +pub(crate) fn pinned_drop(_args: Nothing, mut input: ItemImpl) -> TokenStream {
>> + let mut errors = vec![];
>
> Any reason to not make this `Vec<Error>` and use `syn::Error::combine`?
Is there a way to have an "empty" error? I dislike using `Option<Error>`
here... If not I'll just create my own helper type instead.
Cheers,
Benno
>> + if let Some(unsafety) = input.unsafety {
>> + errors.push(quote_spanned! {unsafety.span=>
>> + ::core::compile_error!("implementing `PinnedDrop` is safe");
>> + });
>> + }
>> + input.unsafety = Some(Token);
>> + match &mut input.trait_ {
>> + Some((not, path, _for)) => {
>> + if let Some(not) = not {
>> + errors.push(quote_spanned! {not.span=>
>> + ::core::compile_error!("cannot implement `!PinnedDrop`");
>> + });
Powered by blists - more mailing lists