Skip to contentSkip to conversation

rust: init: remove old workaround

PATCH In review Tamir Duberstein 3 participants 8 messages Jul 9, 2025 – Jul 14, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover rust: init: remove old workaround

The first patch just enables compilation for these doctests, since I accidentally broke them in v1 of the second patch.

---
Changes in v2:
- Add a commit to compile the doctests.
- Remove a bit more.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Tamir Duberstein (2):
rust: init: compile examples
rust: init: remove old workaround

 rust/kernel/init.rs | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

---
base-commit: 2009a2d5696944d85c34d75e691a6f3884e787c0
change-id: 20250709-init-remove-old-workaround-a6ec6792e010

Best regards,

Signature · 1 line
Tamir Duberstein <[email protected]>
#1 lore raw

PATCH v2 1/2 rust: init: compile examples

It's not exactly clear to me why these were ignored. There are many others like this in pin-init, but I'm only touching the kernel-specific ones here.

---
 rust/kernel/init.rs | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
rust/kernel/init.rs +5 -3
index 8d228c237954..f8402c818d30 100644
@@ -29,15 +29,16 @@
 //!
 //! ## General Examples
 //!
-//! ```rust,ignore
+//! ```rust
 //! # #![allow(clippy::disallowed_names)]
+//! # #![allow(clippy::undocumented_unsafe_blocks)]
 //! use kernel::types::Opaque;
 //! use pin_init::pin_init_from_closure;
 //!
 //! // assume we have some `raw_foo` type in C:
 //! #[repr(C)]
 //! struct RawFoo([u8; 16]);
-//! extern {
+//! extern "C" {
 //!     fn init_foo(_: *mut RawFoo);
 //! }
 //!
@@ -66,12 +67,13 @@
 //! });
 //! ```
 //!
-//! ```rust,ignore
+//! ```rust
 //! # #![allow(unreachable_pub, clippy::disallowed_names)]
 //! use kernel::{prelude::*, types::Opaque};
 //! use core::{ptr::addr_of_mut, marker::PhantomPinned, pin::Pin};
 //! # mod bindings {
 //! #     #![allow(non_camel_case_types)]
+//! #     #![allow(clippy::missing_safety_doc)]
 //! #     pub struct foo;
 //! #     pub unsafe fn init_foo(_ptr: *mut foo) {}
 //! #     pub unsafe fn destroy_foo(_ptr: *mut foo) {}
Signature · 1 line
2.50.0
maintainer
#2 lore raw

Re: [PATCH v2 1/2] rust: init: compile examples

Quoted 3 lines · Tamir Duberstein

It's not exactly clear to me why these were ignored. There are many others like this in pin-init, but I'm only touching the kernel-specific ones here.

Most likely a remnant from 206dea39e559 ("rust: init: disable doctests") that wasn't cleaned up... Thanks!

---
Cheers,
Benno

Quoted 4 lines
---
 rust/kernel/init.rs | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
#3 lore raw

Re: [PATCH v2 1/2] rust: init: compile examples

In reply to Tamir Duberstein
Quoted 6 lines · Tamir Duberstein

It's not exactly clear to me why these were ignored. There are many others like this in pin-init, but I'm only touching the kernel-specific ones here.

This seems essentially equivalent to this one applied a few weeks ago:

    https://lore.kernel.org/rust-for-linux/[email protected]/

But that one uses expect to, which is a bit better for the future.

Cheers,
Miguel

#4 lore raw

Re: [PATCH v2 1/2] rust: init: compile examples

Quoted 7 lines · Miguel Ojeda
Quoted 5 lines · Tamir Duberstein

It's not exactly clear to me why these were ignored. There are many others like this in pin-init, but I'm only touching the kernel-specific ones here.

Quoted 7 lines
Quoted 1 line

This seems essentially equivalent to this one applied a few weeks ago:

    https://lore.kernel.org/rust-for-linux/[email protected]/

But that one uses expect to, which is a bit better for the future.

Yep, thanks!

#5 lore raw

PATCH v2 2/2 rust: init: remove old workaround

In reply to Tamir Duberstein

Error::from_errno is pub since commit 5ed147473458 ("rust: error:
make conversion functions public"), thus remove this workaround which is no longer needed.

---
 rust/kernel/init.rs | 8 --------
 1 file changed, 8 deletions(-)
rust/kernel/init.rs +0 -8
index f8402c818d30..9b3f3e29cc6a 100644
@@ -79,14 +79,6 @@
 //! #     pub unsafe fn destroy_foo(_ptr: *mut foo) {}
 //! #     pub unsafe fn enable_foo(_ptr: *mut foo, _flags: u32) -> i32 { 0 }
 //! # }
-//! # // `Error::from_errno` is `pub(crate)` in the `kernel` crate, thus provide a workaround.
-//! # trait FromErrno {
-//! #     fn from_errno(errno: core::ffi::c_int) -> Error {
-//! #         // Dummy error that can be constructed outside the `kernel` crate.
-//! #         Error::from(core::fmt::Error)
-//! #     }
-//! # }
-//! # impl FromErrno for Error {}
 //! /// # Invariants
 //! ///
 //! /// `foo` is always initialized
Signature · 1 line
2.50.0
maintainer
#7 lore raw
Quoted 11 lines · Miguel Ojeda
Quoted 6 lines · Tamir Duberstein

Error::from_errno is pub since commit 5ed147473458 ("rust: error:
make conversion functions public"), thus remove this workaround which is no longer needed.

This seems the same as this one applied a few weeks ago:

    https://lore.kernel.org/rust-for-linux/[email protected]/

Oh yeah you're right, thanks for the heads-up! (seems like I forgot the patches after applying them so early in the cycle :)

---
Cheers,
Benno