Now that the rusttest target for the macros crate is compiled with the
kernel crate as a dependency, the rest of the rustdoc tests can be
enabled.
Signed-off-by: Ethan D. Twardy <ethan.twardy@gmail.com>
diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs
index 8afed8facb21..6d764099563b 100644
--- a/rust/macros/lib.rs
+++ b/rust/macros/lib.rs
@@ -102,7 +102,9 @@ pub fn module(ts: TokenStream) -> TokenStream {
///
/// # Examples
///
-/// ```ignore
+/// ```rust
+/// # #[macro_use] extern crate macros;
+/// # #[macro_use] extern crate kernel;
/// use kernel::error::VTABLE_DEFAULT_ERROR;
/// use kernel::prelude::*;
///
@@ -147,12 +149,28 @@ pub fn vtable(attr: TokenStream, ts: TokenStream) -> TokenStream {
///
/// # Examples
///
-/// ```ignore
-/// use kernel::macro::concat_idents;
+/// ```rust
+/// # const binder_driver_return_protocol_BR_OK: u32 = 0;
+/// # const binder_driver_return_protocol_BR_ERROR: u32 = 1;
+/// # const binder_driver_return_protocol_BR_TRANSACTION: u32 = 2;
+/// # const binder_driver_return_protocol_BR_REPLY: u32 = 3;
+/// # const binder_driver_return_protocol_BR_DEAD_REPLY: u32 = 4;
+/// # const binder_driver_return_protocol_BR_TRANSACTION_COMPLETE: u32 = 5;
+/// # const binder_driver_return_protocol_BR_INCREFS: u32 = 6;
+/// # const binder_driver_return_protocol_BR_ACQUIRE: u32 = 7;
+/// # const binder_driver_return_protocol_BR_RELEASE: u32 = 8;
+/// # const binder_driver_return_protocol_BR_DECREFS: u32 = 9;
+/// # const binder_driver_return_protocol_BR_NOOP: u32 = 10;
+/// # const binder_driver_return_protocol_BR_SPAWN_LOOPER: u32 = 11;
+/// # const binder_driver_return_protocol_BR_DEAD_BINDER: u32 = 12;
+/// # const binder_driver_return_protocol_BR_CLEAR_DEATH_NOTIFICATION_DONE: u32 = 13;
+/// # const binder_driver_return_protocol_BR_FAILED_REPLY: u32 = 14;
+///
+/// use kernel::macros::concat_idents;
///
/// macro_rules! pub_no_prefix {
/// ($prefix:ident, $($newname:ident),+) => {
-/// $(pub(crate) const $newname: u32 = kernel::macros::concat_idents!($prefix, $newname);)+
+/// $(pub(crate) const $newname: u32 = concat_idents!($prefix, $newname);)+
/// };
/// }
///
@@ -198,8 +216,9 @@ pub fn concat_idents(ts: TokenStream) -> TokenStream {
///
/// # Examples
///
-/// ```rust,ignore
-/// #[pin_data]
+/// ```rust
+/// # use std::{sync::Mutex, process::Command};
+/// #[kernel::macros::pin_data]
/// struct DriverData {
/// #[pin]
/// queue: Mutex<Vec<Command>>,
@@ -207,7 +226,15 @@ pub fn concat_idents(ts: TokenStream) -> TokenStream {
/// }
/// ```
///
-/// ```rust,ignore
+/// ```rust
+/// # use std::{sync::Mutex, process::Command};
+/// # use core::pin::Pin;
+/// # pub struct Info;
+/// # mod bindings {
+/// # pub unsafe fn destroy_info(_ptr: *mut super::Info) {}
+/// # }
+/// use kernel::macros::{pin_data, pinned_drop};
+///
/// #[pin_data(PinnedDrop)]
/// struct DriverData {
/// #[pin]
@@ -222,6 +249,8 @@ pub fn concat_idents(ts: TokenStream) -> TokenStream {
/// unsafe { bindings::destroy_info(self.raw_info) };
/// }
/// }
+///
+/// # fn main() {}
/// ```
///
/// [`pin_init!`]: ../kernel/macro.pin_init.html
@@ -237,13 +266,20 @@ pub fn pin_data(inner: TokenStream, item: TokenStream) -> TokenStream {
///
/// # Examples
///
-/// ```rust,ignore
+/// ```rust
+/// # use macros::{pin_data, pinned_drop};
+/// # use std::{sync::Mutex, process::Command};
+/// # use core::pin::Pin;
+/// # mod bindings {
+/// # pub struct Info;
+/// # pub unsafe fn destroy_info(_ptr: *mut Info) {}
+/// # }
/// #[pin_data(PinnedDrop)]
/// struct DriverData {
/// #[pin]
/// queue: Mutex<Vec<Command>>,
/// buf: Box<[u8; 1024 * 1024]>,
-/// raw_info: *mut Info,
+/// raw_info: *mut bindings::Info,
/// }
///
/// #[pinned_drop]
@@ -408,7 +444,9 @@ pub fn paste(input: TokenStream) -> TokenStream {
///
/// # Examples
///
-/// ```rust,ignore
+/// ```rust
+/// use kernel::macros::Zeroable;
+///
/// #[derive(Zeroable)]
/// pub struct DriverData {
/// id: i64,
--
2.44.2
On Mon, Jun 24, 2024 at 5:04 AM Ethan D. Twardy <ethan.twardy@gmail.com> wrote:
>
> Now that the rusttest target for the macros crate is compiled with the
> kernel crate as a dependency, the rest of the rustdoc tests can be
> enabled.
>
> Signed-off-by: Ethan D. Twardy <ethan.twardy@gmail.com>
>
> diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs
> index 8afed8facb21..6d764099563b 100644
> --- a/rust/macros/lib.rs
> +++ b/rust/macros/lib.rs
> @@ -102,7 +102,9 @@ pub fn module(ts: TokenStream) -> TokenStream {
> ///
> /// # Examples
> ///
> -/// ```ignore
> +/// ```rust
> +/// # #[macro_use] extern crate macros;
> +/// # #[macro_use] extern crate kernel;
You also added these lines in patch 2, but you did not make them hidden there.
> /// use kernel::error::VTABLE_DEFAULT_ERROR;
> /// use kernel::prelude::*;
> ///
> @@ -147,12 +149,28 @@ pub fn vtable(attr: TokenStream, ts: TokenStream) -> TokenStream {
> ///
> /// # Examples
> ///
> -/// ```ignore
> -/// use kernel::macro::concat_idents;
> +/// ```rust
> +/// # const binder_driver_return_protocol_BR_OK: u32 = 0;
> +/// # const binder_driver_return_protocol_BR_ERROR: u32 = 1;
> +/// # const binder_driver_return_protocol_BR_TRANSACTION: u32 = 2;
> +/// # const binder_driver_return_protocol_BR_REPLY: u32 = 3;
> +/// # const binder_driver_return_protocol_BR_DEAD_REPLY: u32 = 4;
> +/// # const binder_driver_return_protocol_BR_TRANSACTION_COMPLETE: u32 = 5;
> +/// # const binder_driver_return_protocol_BR_INCREFS: u32 = 6;
> +/// # const binder_driver_return_protocol_BR_ACQUIRE: u32 = 7;
> +/// # const binder_driver_return_protocol_BR_RELEASE: u32 = 8;
> +/// # const binder_driver_return_protocol_BR_DECREFS: u32 = 9;
> +/// # const binder_driver_return_protocol_BR_NOOP: u32 = 10;
> +/// # const binder_driver_return_protocol_BR_SPAWN_LOOPER: u32 = 11;
> +/// # const binder_driver_return_protocol_BR_DEAD_BINDER: u32 = 12;
> +/// # const binder_driver_return_protocol_BR_CLEAR_DEATH_NOTIFICATION_DONE: u32 = 13;
> +/// # const binder_driver_return_protocol_BR_FAILED_REPLY: u32 = 14;
> +///
> +/// use kernel::macros::concat_idents;
The empty line above this import should probably be removed to improve
how this is rendered.
> ///
> /// macro_rules! pub_no_prefix {
> /// ($prefix:ident, $($newname:ident),+) => {
> -/// $(pub(crate) const $newname: u32 = kernel::macros::concat_idents!($prefix, $newname);)+
> +/// $(pub(crate) const $newname: u32 = concat_idents!($prefix, $newname);)+
> /// };
> /// }
> ///
> @@ -198,8 +216,9 @@ pub fn concat_idents(ts: TokenStream) -> TokenStream {
> ///
> /// # Examples
> ///
> -/// ```rust,ignore
> -/// #[pin_data]
> +/// ```rust
> +/// # use std::{sync::Mutex, process::Command};
> +/// #[kernel::macros::pin_data]
> /// struct DriverData {
I'm pretty sure `#[pin_data]` is in our prelude and doesn't need an
import in normal code. If it needs an import in the test, then please
add a hidden import rather than using the full path.
> /// #[pin]
> /// queue: Mutex<Vec<Command>>,
> @@ -207,7 +226,15 @@ pub fn concat_idents(ts: TokenStream) -> TokenStream {
> /// }
> /// ```
> ///
> -/// ```rust,ignore
> +/// ```rust
> +/// # use std::{sync::Mutex, process::Command};
> +/// # use core::pin::Pin;
> +/// # pub struct Info;
> +/// # mod bindings {
> +/// # pub unsafe fn destroy_info(_ptr: *mut super::Info) {}
> +/// # }
> +/// use kernel::macros::{pin_data, pinned_drop};
> +///
> /// #[pin_data(PinnedDrop)]
> /// struct DriverData {
> /// #[pin]
> @@ -222,6 +249,8 @@ pub fn concat_idents(ts: TokenStream) -> TokenStream {
> /// unsafe { bindings::destroy_info(self.raw_info) };
> /// }
> /// }
> +///
> +/// # fn main() {}
> /// ```
> ///
> /// [`pin_init!`]: ../kernel/macro.pin_init.html
> @@ -237,13 +266,20 @@ pub fn pin_data(inner: TokenStream, item: TokenStream) -> TokenStream {
> ///
> /// # Examples
> ///
> -/// ```rust,ignore
> +/// ```rust
> +/// # use macros::{pin_data, pinned_drop};
> +/// # use std::{sync::Mutex, process::Command};
> +/// # use core::pin::Pin;
> +/// # mod bindings {
> +/// # pub struct Info;
> +/// # pub unsafe fn destroy_info(_ptr: *mut Info) {}
> +/// # }
> /// #[pin_data(PinnedDrop)]
> /// struct DriverData {
> /// #[pin]
> /// queue: Mutex<Vec<Command>>,
> /// buf: Box<[u8; 1024 * 1024]>,
> -/// raw_info: *mut Info,
> +/// raw_info: *mut bindings::Info,
> /// }
> ///
> /// #[pinned_drop]
> @@ -408,7 +444,9 @@ pub fn paste(input: TokenStream) -> TokenStream {
> ///
> /// # Examples
> ///
> -/// ```rust,ignore
> +/// ```rust
> +/// use kernel::macros::Zeroable;
> +///
> /// #[derive(Zeroable)]
> /// pub struct DriverData {
> /// id: i64,
> --
> 2.44.2
>
On Mon Jun 24, 2024 at 3:47 AM CDT, Alice Ryhl wrote:
> On Mon, Jun 24, 2024 at 5:04 AM Ethan D. Twardy <ethan.twardy@gmail.com> wrote:
> >
> > Now that the rusttest target for the macros crate is compiled with the
> > kernel crate as a dependency, the rest of the rustdoc tests can be
> > enabled.
> >
> > Signed-off-by: Ethan D. Twardy <ethan.twardy@gmail.com>
> >
> > diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs
> > index 8afed8facb21..6d764099563b 100644
> > --- a/rust/macros/lib.rs
> > +++ b/rust/macros/lib.rs
> > @@ -102,7 +102,9 @@ pub fn module(ts: TokenStream) -> TokenStream {
> > ///
> > /// # Examples
> > ///
> > -/// ```ignore
> > +/// ```rust
> > +/// # #[macro_use] extern crate macros;
> > +/// # #[macro_use] extern crate kernel;
>
> You also added these lines in patch 2, but you did not make them hidden there.
>
I made these hidden in patch 2, since I would not expect them to be
necessary in normal kernel code. Please let me know if that's not the
case!
> The empty line above this import should probably be removed to improve
> how this is rendered.
And
> I'm pretty sure `#[pin_data]` is in our prelude and doesn't need an
> import in normal code. If it needs an import in the test, then please
> add a hidden import rather than using the full path.
Will also land in v2. Thank you very much for your time in reviewing
this patch series! Did you intend to offer your Reviewed-by signoff for
this patch (4/4) as well?
Ethan
© 2016 - 2025 Red Hat, Inc.