xref: /linux/rust/pin-init/internal/src/lib.rs (revision 7cb5dee4c8349f8cc3e1ce529df4e18ebe3fed2e)
1 // SPDX-License-Identifier: Apache-2.0 OR MIT
2 
3 // When fixdep scans this, it will find this string `CONFIG_RUSTC_VERSION_TEXT`
4 // and thus add a dependency on `include/config/RUSTC_VERSION_TEXT`, which is
5 // touched by Kconfig when the version string from the compiler changes.
6 
7 //! `pin-init` proc macros.
8 
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)]
17 
18 use proc_macro::TokenStream;
19 
20 #[cfg(kernel)]
21 #[path = "../../../macros/quote.rs"]
22 #[macro_use]
23 mod quote;
24 #[cfg(not(kernel))]
25 #[macro_use]
26 extern crate quote;
27 
28 mod helpers;
29 mod pin_data;
30 mod pinned_drop;
31 mod zeroable;
32 
33 #[allow(missing_docs)]
34 #[proc_macro_attribute]
35 pub fn pin_data(inner: TokenStream, item: TokenStream) -> TokenStream {
36     pin_data::pin_data(inner.into(), item.into()).into()
37 }
38 
39 #[allow(missing_docs)]
40 #[proc_macro_attribute]
41 pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
42     pinned_drop::pinned_drop(args.into(), input.into()).into()
43 }
44 
45 #[allow(missing_docs)]
46 #[proc_macro_derive(Zeroable)]
47 pub fn derive_zeroable(input: TokenStream) -> TokenStream {
48     zeroable::derive(input.into()).into()
49 }
50