All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fiona Behrens <me@kloenk.dev>
To: Benno Lossin <benno.lossin@proton.me>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 18/22] rust: pin-init: internal: synchronize with user-space version
Date: Thu, 13 Mar 2025 12:22:52 +0100	[thread overview]
Message-ID: <m2tt7xxjhv.fsf@kloenk.dev> (raw)
In-Reply-To: <20250308110339.2997091-19-benno.lossin@proton.me> (Benno Lossin's message of "Sat, 08 Mar 2025 11:05:22 +0000")

Benno Lossin <benno.lossin@proton.me> writes:

> Synchronize the internal macros crate with the user-space version that
> uses the quote crate [1] instead of a custom `quote!` macro. The imports
> in the different version are achieved using `cfg` on the kernel config
> value. This cfg is always set in the kernel and never set in the
> user-space version.
>
> Since the quote crate requires the proc_macro2 crate, imports also need
> to be adjusted and `.into()` calls have to be inserted.
>
> Link: https://crates.io/crates/quote [1]
> Signed-off-by: Benno Lossin <benno.lossin@proton.me>
> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
> Tested-by: Andreas Hindborg <a.hindborg@kernel.org>

Reviewed-by: Fiona Behrens <me@Kloenk.dev>

> ---
>  rust/pin-init/internal/src/helpers.rs     |  3 +++
>  rust/pin-init/internal/src/lib.rs         | 16 +++++++++++++---
>  rust/pin-init/internal/src/pin_data.rs    |  3 +++
>  rust/pin-init/internal/src/pinned_drop.rs |  3 +++
>  rust/pin-init/internal/src/zeroable.rs    |  3 +++
>  5 files changed, 25 insertions(+), 3 deletions(-)
>
> diff --git a/rust/pin-init/internal/src/helpers.rs b/rust/pin-init/internal/src/helpers.rs
> index 78521ba19d0b..236f989a50f2 100644
> --- a/rust/pin-init/internal/src/helpers.rs
> +++ b/rust/pin-init/internal/src/helpers.rs
> @@ -1,5 +1,8 @@
>  // SPDX-License-Identifier: Apache-2.0 OR MIT
>  
> +#[cfg(not(kernel))]
> +use proc_macro2 as proc_macro;
> +
>  use proc_macro::{TokenStream, TokenTree};
>  
>  /// Parsed generics.
> diff --git a/rust/pin-init/internal/src/lib.rs b/rust/pin-init/internal/src/lib.rs
> index c201b8a53915..30e145f80bc0 100644
> --- a/rust/pin-init/internal/src/lib.rs
> +++ b/rust/pin-init/internal/src/lib.rs
> @@ -7,6 +7,13 @@
>  //! `pin-init` proc macros.
>  
>  #![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
> +// Allow `.into()` to convert
> +// - `proc_macro2::TokenStream` into `proc_macro::TokenStream` in the user-space version.
> +// - `proc_macro::TokenStream` into `proc_macro::TokenStream` in the kernel version.
> +//   Clippy warns on this conversion, but it's required by the user-space version.
> +//
> +// Remove once we have `proc_macro2` in the kernel.
> +#![allow(clippy::useless_conversion)]
>  
>  use proc_macro::TokenStream;
>  
> @@ -14,6 +21,9 @@
>  #[path = "../../../macros/quote.rs"]
>  #[macro_use]
>  mod quote;
> +#[cfg(not(kernel))]
> +#[macro_use]
> +extern crate quote;
>  
>  mod helpers;
>  mod pin_data;
> @@ -23,17 +33,17 @@
>  #[allow(missing_docs)]
>  #[proc_macro_attribute]
>  pub fn pin_data(inner: TokenStream, item: TokenStream) -> TokenStream {
> -    pin_data::pin_data(inner, item)
> +    pin_data::pin_data(inner.into(), item.into()).into()
>  }
>  
>  #[allow(missing_docs)]
>  #[proc_macro_attribute]
>  pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
> -    pinned_drop::pinned_drop(args, input)
> +    pinned_drop::pinned_drop(args.into(), input.into()).into()
>  }
>  
>  #[allow(missing_docs)]
>  #[proc_macro_derive(Zeroable)]
>  pub fn derive_zeroable(input: TokenStream) -> TokenStream {
> -    zeroable::derive(input)
> +    zeroable::derive(input.into()).into()
>  }
> diff --git a/rust/pin-init/internal/src/pin_data.rs b/rust/pin-init/internal/src/pin_data.rs
> index 9b974498f4a8..87d4a7eb1d35 100644
> --- a/rust/pin-init/internal/src/pin_data.rs
> +++ b/rust/pin-init/internal/src/pin_data.rs
> @@ -1,5 +1,8 @@
>  // SPDX-License-Identifier: Apache-2.0 OR MIT
>  
> +#[cfg(not(kernel))]
> +use proc_macro2 as proc_macro;
> +
>  use crate::helpers::{parse_generics, Generics};
>  use proc_macro::{Group, Punct, Spacing, TokenStream, TokenTree};
>  
> diff --git a/rust/pin-init/internal/src/pinned_drop.rs b/rust/pin-init/internal/src/pinned_drop.rs
> index 386f52f73c06..c824dd8b436d 100644
> --- a/rust/pin-init/internal/src/pinned_drop.rs
> +++ b/rust/pin-init/internal/src/pinned_drop.rs
> @@ -1,5 +1,8 @@
>  // SPDX-License-Identifier: Apache-2.0 OR MIT
>  
> +#[cfg(not(kernel))]
> +use proc_macro2 as proc_macro;
> +
>  use proc_macro::{TokenStream, TokenTree};
>  
>  pub(crate) fn pinned_drop(_args: TokenStream, input: TokenStream) -> TokenStream {
> diff --git a/rust/pin-init/internal/src/zeroable.rs b/rust/pin-init/internal/src/zeroable.rs
> index 0cf6732f27dc..acc94008c152 100644
> --- a/rust/pin-init/internal/src/zeroable.rs
> +++ b/rust/pin-init/internal/src/zeroable.rs
> @@ -1,5 +1,8 @@
>  // SPDX-License-Identifier: GPL-2.0
>  
> +#[cfg(not(kernel))]
> +use proc_macro2 as proc_macro;
> +
>  use crate::helpers::{parse_generics, Generics};
>  use proc_macro::{TokenStream, TokenTree};

  reply	other threads:[~2025-03-13 11:22 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-08 11:03 [PATCH v2 00/22] make pin-init into a standalone crate Benno Lossin
2025-03-08 11:03 ` [PATCH v2 01/22] rust: init: disable doctests Benno Lossin
2025-03-08 11:04 ` [PATCH v2 02/22] rust: move pin-init API into its own directory Benno Lossin
2025-03-08 11:04 ` [PATCH v2 03/22] rust: add extensions to the pin-init crate and move relevant documentation there Benno Lossin
2025-03-18 11:32   ` Andreas Hindborg
2025-03-08 11:04 ` [PATCH v2 04/22] rust: pin-init: move proc-macro documentation into pin-init crate Benno Lossin
2025-03-18 11:33   ` Andreas Hindborg
2025-03-19 13:14     ` Miguel Ojeda
2025-03-08 11:04 ` [PATCH v2 05/22] rust: pin-init: change examples to the user-space version Benno Lossin
2025-03-08 11:04 ` [PATCH v2 06/22] rust: pin-init: call `try_[pin_]init!` from `[pin_]init!` instead of `__init_internal!` Benno Lossin
2025-03-08 11:04 ` [PATCH v2 07/22] rust: pin-init: move the default error behavior of `try_[pin_]init` Benno Lossin
2025-03-08 11:04 ` [PATCH v2 08/22] rust: pin-init: move `InPlaceInit` and impls of `InPlaceWrite` into the kernel crate Benno Lossin
2025-03-18 11:37   ` Andreas Hindborg
2025-03-08 11:04 ` [PATCH v2 09/22] rust: pin-init: move impl `Zeroable` for `Opaque` and `Option<KBox<T>>` " Benno Lossin
2025-03-13 11:16   ` Fiona Behrens
2025-03-08 11:04 ` [PATCH v2 10/22] rust: add `ZeroableOption` and implement it instead of `Zeroable` for `Option<Box<T, A>>` Benno Lossin
2025-03-08 11:04 ` [PATCH v2 11/22] rust: pin-init: fix documentation links Benno Lossin
2025-03-18 11:38   ` Andreas Hindborg
2025-03-08 11:04 ` [PATCH v2 12/22] rust: pin-init: remove kernel-crate dependency Benno Lossin
2025-03-08 11:04 ` [PATCH v2 13/22] rust: pin-init: change the way the `paste!` macro is called Benno Lossin
2025-03-08 11:05 ` [PATCH v2 14/22] rust: add pin-init crate build infrastructure Benno Lossin
2025-03-08 11:05 ` [PATCH v2 15/22] rust: make pin-init its own crate Benno Lossin
2025-03-18 11:40   ` Andreas Hindborg
2025-03-08 11:05 ` [PATCH v2 16/22] rust: pin-init: add `std` and `alloc` support from the user-space version Benno Lossin
2025-03-08 11:05 ` [PATCH v2 17/22] rust: pin-init: synchronize documentation with " Benno Lossin
2025-03-08 11:05 ` [PATCH v2 18/22] rust: pin-init: internal: synchronize with " Benno Lossin
2025-03-13 11:22   ` Fiona Behrens [this message]
2025-03-08 11:05 ` [PATCH v2 19/22] rust: pin-init: miscellaneous synchronization with the " Benno Lossin
2025-03-13 11:24   ` Fiona Behrens
2025-03-08 11:05 ` [PATCH v2 20/22] rust: pin-init: add miscellaneous files from " Benno Lossin
2025-03-08 11:05 ` [PATCH v2 21/22] rust: pin-init: re-enable doctests Benno Lossin
2025-03-08 11:05 ` [PATCH v2 22/22] MAINTAINERS: add entry for the `pin-init` crate Benno Lossin
2025-03-16 21:07 ` [PATCH v2 00/22] make pin-init into a standalone crate Miguel Ojeda
2025-03-17 10:45   ` Benno Lossin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2tt7xxjhv.fsf@kloenk.dev \
    --to=me@kloenk.dev \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.