Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/rust/pin-init/internal/src/lib.rs
29281 views
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
// Documentation is done in the pin-init crate instead.
18
#![allow(missing_docs)]
19
20
use proc_macro::TokenStream;
21
22
#[cfg(kernel)]
23
#[path = "../../../macros/quote.rs"]
24
#[macro_use]
25
#[cfg_attr(not(kernel), rustfmt::skip)]
26
mod quote;
27
#[cfg(not(kernel))]
28
#[macro_use]
29
extern crate quote;
30
31
mod helpers;
32
mod pin_data;
33
mod pinned_drop;
34
mod zeroable;
35
36
#[proc_macro_attribute]
37
pub fn pin_data(inner: TokenStream, item: TokenStream) -> TokenStream {
38
pin_data::pin_data(inner.into(), item.into()).into()
39
}
40
41
#[proc_macro_attribute]
42
pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
43
pinned_drop::pinned_drop(args.into(), input.into()).into()
44
}
45
46
#[proc_macro_derive(Zeroable)]
47
pub fn derive_zeroable(input: TokenStream) -> TokenStream {
48
zeroable::derive(input.into()).into()
49
}
50
51
#[proc_macro_derive(MaybeZeroable)]
52
pub fn maybe_derive_zeroable(input: TokenStream) -> TokenStream {
53
zeroable::maybe_derive(input.into()).into()
54
}
55
56