Skip to content

Commit 5115b02

Browse files
committed
rust: macros: replace quote! with quote::quote and use proc-macro2
We now have access to the `quote` crate providing the `quote!` macro that does the same (and more) as our own `quote!` macro. Thus replace our own version with the one from the crate. Since the `quote` crate uses the `proc-macro2` library, we also use that in our macros instead of `proc-macro`. Signed-off-by: Benno Lossin <benno.lossin@proton.me>
1 parent c44ec41 commit 5115b02

10 files changed

Lines changed: 22 additions & 174 deletions

File tree

rust/macros/concat_idents.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3-
use proc_macro::{token_stream, Ident, TokenStream, TokenTree};
3+
use proc_macro2::{token_stream, Ident, TokenStream, TokenTree};
44

55
use crate::helpers::expect_punct;
66

rust/macros/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3-
use proc_macro::{token_stream, Group, TokenStream, TokenTree};
3+
use proc_macro2::{token_stream, Group, TokenStream, TokenTree};
44

55
pub(crate) fn try_ident(it: &mut token_stream::IntoIter) -> Option<String> {
66
if let Some(TokenTree::Ident(ident)) = it.next() {

rust/macros/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
//! Crate for all kernel procedural macros.
44
5-
#[macro_use]
6-
mod quote;
75
mod concat_idents;
86
mod helpers;
97
mod module;
@@ -76,7 +74,7 @@ use proc_macro::TokenStream;
7674
/// - `alias`: byte array of alias name of the kernel module.
7775
#[proc_macro]
7876
pub fn module(ts: TokenStream) -> TokenStream {
79-
module::module(ts)
77+
module::module(ts.into()).into()
8078
}
8179

8280
/// Declares or implements a vtable trait.
@@ -151,7 +149,7 @@ pub fn module(ts: TokenStream) -> TokenStream {
151149
/// [`kernel::error::VTABLE_DEFAULT_ERROR`]: ../kernel/error/constant.VTABLE_DEFAULT_ERROR.html
152150
#[proc_macro_attribute]
153151
pub fn vtable(attr: TokenStream, ts: TokenStream) -> TokenStream {
154-
vtable::vtable(attr, ts)
152+
vtable::vtable(attr.into(), ts.into()).into()
155153
}
156154

157155
/// Concatenate two identifiers.
@@ -194,7 +192,7 @@ pub fn vtable(attr: TokenStream, ts: TokenStream) -> TokenStream {
194192
/// ```
195193
#[proc_macro]
196194
pub fn concat_idents(ts: TokenStream) -> TokenStream {
197-
concat_idents::concat_idents(ts)
195+
concat_idents::concat_idents(ts.into()).into()
198196
}
199197

200198
/// Used to specify the pinning information of the fields of a struct.
@@ -243,7 +241,7 @@ pub fn concat_idents(ts: TokenStream) -> TokenStream {
243241
// ^ cannot use direct link, since `kernel` is not a dependency of `macros`.
244242
#[proc_macro_attribute]
245243
pub fn pin_data(inner: TokenStream, item: TokenStream) -> TokenStream {
246-
pin_data::pin_data(inner, item)
244+
pin_data::pin_data(inner.into(), item.into()).into()
247245
}
248246

249247
/// Used to implement `PinnedDrop` safely.
@@ -270,7 +268,7 @@ pub fn pin_data(inner: TokenStream, item: TokenStream) -> TokenStream {
270268
/// ```
271269
#[proc_macro_attribute]
272270
pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
273-
pinned_drop::pinned_drop(args, input)
271+
pinned_drop::pinned_drop(args.into(), input.into()).into()
274272
}
275273

276274
/// Paste identifiers together.
@@ -382,9 +380,13 @@ pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
382380
/// [`paste`]: https://docs.rs/paste/
383381
#[proc_macro]
384382
pub fn paste(input: TokenStream) -> TokenStream {
383+
let input: proc_macro2::TokenStream = input.into();
385384
let mut tokens = input.into_iter().collect();
386385
paste::expand(&mut tokens);
387-
tokens.into_iter().collect()
386+
tokens
387+
.into_iter()
388+
.collect::<proc_macro2::TokenStream>()
389+
.into()
388390
}
389391

390392
/// Derives the [`Zeroable`] trait for the given struct.
@@ -403,5 +405,5 @@ pub fn paste(input: TokenStream) -> TokenStream {
403405
/// ```
404406
#[proc_macro_derive(Zeroable)]
405407
pub fn derive_zeroable(input: TokenStream) -> TokenStream {
406-
zeroable::derive(input)
408+
zeroable::derive(input.into()).into()
407409
}

rust/macros/module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22

33
use crate::helpers::*;
4-
use proc_macro::{token_stream, Delimiter, Literal, TokenStream, TokenTree};
4+
use proc_macro2::{token_stream, Delimiter, Literal, TokenStream, TokenTree};
55
use std::fmt::Write;
66

77
fn expect_string_array(it: &mut token_stream::IntoIter) -> Vec<String> {

rust/macros/paste.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3-
use proc_macro::{Delimiter, Group, Ident, Spacing, Span, TokenTree};
3+
use proc_macro2::{Delimiter, Group, Ident, Spacing, Span, TokenTree};
44

55
fn concat(tokens: &[TokenTree], group_span: Span) -> TokenTree {
66
let mut tokens = tokens.iter();

rust/macros/pin_data.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// SPDX-License-Identifier: Apache-2.0 OR MIT
22

33
use crate::helpers::{parse_generics, Generics};
4-
use proc_macro::{Group, Punct, Spacing, TokenStream, TokenTree};
4+
use proc_macro2::{Group, Punct, Spacing, TokenStream, TokenTree};
5+
use quote::quote;
56

67
pub(crate) fn pin_data(args: TokenStream, input: TokenStream) -> TokenStream {
78
// This proc-macro only does some pre-parsing and then delegates the actual parsing to

rust/macros/pinned_drop.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0 OR MIT
22

3-
use proc_macro::{TokenStream, TokenTree};
3+
use proc_macro2::{TokenStream, TokenTree};
4+
use quote::quote;
45

56
pub(crate) fn pinned_drop(_args: TokenStream, input: TokenStream) -> TokenStream {
67
let mut toks = input.into_iter().collect::<Vec<_>>();

rust/macros/quote.rs

Lines changed: 0 additions & 157 deletions
This file was deleted.

rust/macros/vtable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3-
use proc_macro::{Delimiter, Group, TokenStream, TokenTree};
3+
use proc_macro2::{Delimiter, Group, TokenStream, TokenTree};
44
use std::collections::HashSet;
55
use std::fmt::Write;
66

rust/macros/zeroable.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// SPDX-License-Identifier: GPL-2.0
22

33
use crate::helpers::{parse_generics, Generics};
4-
use proc_macro::{TokenStream, TokenTree};
4+
use proc_macro2::{TokenStream, TokenTree};
5+
use quote::quote;
56

67
pub(crate) fn derive(input: TokenStream) -> TokenStream {
78
let (

0 commit comments

Comments
 (0)