Skip to content

Commit 7cb5dee

Browse files
y86-devojeda
authored andcommitted
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 <[email protected]> Reviewed-by: Andreas Hindborg <[email protected]> Tested-by: Andreas Hindborg <[email protected]> Reviewed-by: Fiona Behrens <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 02c01c0 commit 7cb5dee

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

rust/pin-init/internal/src/helpers.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// SPDX-License-Identifier: Apache-2.0 OR MIT
22

3+
#[cfg(not(kernel))]
4+
use proc_macro2 as proc_macro;
5+
36
use proc_macro::{TokenStream, TokenTree};
47

58
/// Parsed generics.

rust/pin-init/internal/src/lib.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,23 @@
77
//! `pin-init` proc macros.
88
99
#![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)]
1017

1118
use proc_macro::TokenStream;
1219

1320
#[cfg(kernel)]
1421
#[path = "../../../macros/quote.rs"]
1522
#[macro_use]
1623
mod quote;
24+
#[cfg(not(kernel))]
25+
#[macro_use]
26+
extern crate quote;
1727

1828
mod helpers;
1929
mod pin_data;
@@ -23,17 +33,17 @@ mod zeroable;
2333
#[allow(missing_docs)]
2434
#[proc_macro_attribute]
2535
pub fn pin_data(inner: TokenStream, item: TokenStream) -> TokenStream {
26-
pin_data::pin_data(inner, item)
36+
pin_data::pin_data(inner.into(), item.into()).into()
2737
}
2838

2939
#[allow(missing_docs)]
3040
#[proc_macro_attribute]
3141
pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
32-
pinned_drop::pinned_drop(args, input)
42+
pinned_drop::pinned_drop(args.into(), input.into()).into()
3343
}
3444

3545
#[allow(missing_docs)]
3646
#[proc_macro_derive(Zeroable)]
3747
pub fn derive_zeroable(input: TokenStream) -> TokenStream {
38-
zeroable::derive(input)
48+
zeroable::derive(input.into()).into()
3949
}

rust/pin-init/internal/src/pin_data.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// SPDX-License-Identifier: Apache-2.0 OR MIT
22

3+
#[cfg(not(kernel))]
4+
use proc_macro2 as proc_macro;
5+
36
use crate::helpers::{parse_generics, Generics};
47
use proc_macro::{Group, Punct, Spacing, TokenStream, TokenTree};
58

rust/pin-init/internal/src/pinned_drop.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// SPDX-License-Identifier: Apache-2.0 OR MIT
22

3+
#[cfg(not(kernel))]
4+
use proc_macro2 as proc_macro;
5+
36
use proc_macro::{TokenStream, TokenTree};
47

58
pub(crate) fn pinned_drop(_args: TokenStream, input: TokenStream) -> TokenStream {

rust/pin-init/internal/src/zeroable.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3+
#[cfg(not(kernel))]
4+
use proc_macro2 as proc_macro;
5+
36
use crate::helpers::{parse_generics, Generics};
47
use proc_macro::{TokenStream, TokenTree};
58

0 commit comments

Comments
 (0)