]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: allow `unreachable_pub` for doctests
authorMiguel Ojeda <ojeda@kernel.org>
Mon, 10 Nov 2025 11:35:27 +0000 (12:35 +0100)
committerMiguel Ojeda <ojeda@kernel.org>
Mon, 17 Nov 2025 07:41:31 +0000 (08:41 +0100)
Examples (i.e. doctests) may want to show public items such as structs,
thus the `unreachable_pub` warning is not very helpful.

Thus allow it for all doctests.

In addition, remove it from the existing `expect`s we have in a couple
doctests.

Suggested-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/rust-for-linux/aRG9VjsaCjsvAwUn@google.com/
Reviewed-by: David Gow <davidgow@google.com>
Acked-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20251110113528.1658238-1-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/init.rs
rust/kernel/types.rs
scripts/rustdoc_test_gen.rs

index 4949047af8d7fdf10f5a670e5e581b452beb3d6b..e476d81c1a27d00c88b87041c6b0abc6e5489bb4 100644 (file)
@@ -67,7 +67,7 @@
 //! ```
 //!
 //! ```rust
-//! # #![expect(unreachable_pub, clippy::disallowed_names)]
+//! # #![expect(clippy::disallowed_names)]
 //! use kernel::{prelude::*, types::Opaque};
 //! use core::{ptr::addr_of_mut, marker::PhantomPinned, pin::Pin};
 //! # mod bindings {
index dc0a02f5c3cfc532d1fa5f209b40dd79cbe0fb37..8358247885065abc1fa888f06c566d37bb92fc56 100644 (file)
@@ -289,7 +289,7 @@ impl<T, F: FnOnce(T)> Drop for ScopeGuard<T, F> {
 /// # Examples
 ///
 /// ```
-/// # #![expect(unreachable_pub, clippy::disallowed_names)]
+/// # #![expect(clippy::disallowed_names)]
 /// use kernel::types::Opaque;
 /// # // Emulate a C struct binding which is from C, maybe uninitialized or not, only the C side
 /// # // knows.
index c8f9dc2ab976c2d844390dc314e1bd317b0ae8c3..0e6a0542d1bdc2b0dbca0abda7a6a1dcc87b2557 100644 (file)
@@ -208,6 +208,7 @@ pub extern "C" fn {kunit_name}(__kunit_test: *mut ::kernel::bindings::kunit) {{
     #[allow(unused)]
     static __DOCTEST_ANCHOR: i32 = ::core::line!() as i32 + {body_offset} + 1;
     {{
+        #![allow(unreachable_pub)]
         {body}
         main();
     }}