Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: pin-init: internal: synchronize with user-space version

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>
Link: https://lore.kernel.org/r/20250308110339.2997091-19-benno.lossin@proton.me
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

authored by

Benno Lossin and committed by
Miguel Ojeda
7cb5dee4 02c01c08

+25 -3
+3
rust/pin-init/internal/src/helpers.rs
··· 1 1 // SPDX-License-Identifier: Apache-2.0 OR MIT 2 2 3 + #[cfg(not(kernel))] 4 + use proc_macro2 as proc_macro; 5 + 3 6 use proc_macro::{TokenStream, TokenTree}; 4 7 5 8 /// Parsed generics.
+13 -3
rust/pin-init/internal/src/lib.rs
··· 7 7 //! `pin-init` proc macros. 8 8 9 9 #![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] 10 + // Allow `.into()` to convert 11 + // - `proc_macro2::TokenStream` into `proc_macro::TokenStream` in the user-space version. 12 + // - `proc_macro::TokenStream` into `proc_macro::TokenStream` in the kernel version. 13 + // Clippy warns on this conversion, but it's required by the user-space version. 14 + // 15 + // Remove once we have `proc_macro2` in the kernel. 16 + #![allow(clippy::useless_conversion)] 10 17 11 18 use proc_macro::TokenStream; 12 19 ··· 21 14 #[path = "../../../macros/quote.rs"] 22 15 #[macro_use] 23 16 mod quote; 17 + #[cfg(not(kernel))] 18 + #[macro_use] 19 + extern crate quote; 24 20 25 21 mod helpers; 26 22 mod pin_data; ··· 33 23 #[allow(missing_docs)] 34 24 #[proc_macro_attribute] 35 25 pub fn pin_data(inner: TokenStream, item: TokenStream) -> TokenStream { 36 - pin_data::pin_data(inner, item) 26 + pin_data::pin_data(inner.into(), item.into()).into() 37 27 } 38 28 39 29 #[allow(missing_docs)] 40 30 #[proc_macro_attribute] 41 31 pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream { 42 - pinned_drop::pinned_drop(args, input) 32 + pinned_drop::pinned_drop(args.into(), input.into()).into() 43 33 } 44 34 45 35 #[allow(missing_docs)] 46 36 #[proc_macro_derive(Zeroable)] 47 37 pub fn derive_zeroable(input: TokenStream) -> TokenStream { 48 - zeroable::derive(input) 38 + zeroable::derive(input.into()).into() 49 39 }
+3
rust/pin-init/internal/src/pin_data.rs
··· 1 1 // SPDX-License-Identifier: Apache-2.0 OR MIT 2 2 3 + #[cfg(not(kernel))] 4 + use proc_macro2 as proc_macro; 5 + 3 6 use crate::helpers::{parse_generics, Generics}; 4 7 use proc_macro::{Group, Punct, Spacing, TokenStream, TokenTree}; 5 8
+3
rust/pin-init/internal/src/pinned_drop.rs
··· 1 1 // SPDX-License-Identifier: Apache-2.0 OR MIT 2 2 3 + #[cfg(not(kernel))] 4 + use proc_macro2 as proc_macro; 5 + 3 6 use proc_macro::{TokenStream, TokenTree}; 4 7 5 8 pub(crate) fn pinned_drop(_args: TokenStream, input: TokenStream) -> TokenStream {
+3
rust/pin-init/internal/src/zeroable.rs
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 + #[cfg(not(kernel))] 4 + use proc_macro2 as proc_macro; 5 + 3 6 use crate::helpers::{parse_generics, Generics}; 4 7 use proc_macro::{TokenStream, TokenTree}; 5 8