rust: allow `unreachable_pub` for doctests

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>
This commit is contained in:
Miguel Ojeda 2025-11-10 12:35:27 +01:00
parent bf724be7f0
commit ab844cf320
3 changed files with 3 additions and 2 deletions

View File

@ -67,7 +67,7 @@
//! ``` //! ```
//! //!
//! ```rust //! ```rust
//! # #![expect(unreachable_pub, clippy::disallowed_names)] //! # #![expect(clippy::disallowed_names)]
//! use kernel::{prelude::*, types::Opaque}; //! use kernel::{prelude::*, types::Opaque};
//! use core::{ptr::addr_of_mut, marker::PhantomPinned, pin::Pin}; //! use core::{ptr::addr_of_mut, marker::PhantomPinned, pin::Pin};
//! # mod bindings { //! # mod bindings {

View File

@ -289,7 +289,7 @@ fn drop(&mut self) {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # #![expect(unreachable_pub, clippy::disallowed_names)] /// # #![expect(clippy::disallowed_names)]
/// use kernel::types::Opaque; /// use kernel::types::Opaque;
/// # // Emulate a C struct binding which is from C, maybe uninitialized or not, only the C side /// # // Emulate a C struct binding which is from C, maybe uninitialized or not, only the C side
/// # // knows. /// # // knows.

View File

@ -208,6 +208,7 @@ macro_rules! assert_eq {{
#[allow(unused)] #[allow(unused)]
static __DOCTEST_ANCHOR: i32 = ::core::line!() as i32 + {body_offset} + 1; static __DOCTEST_ANCHOR: i32 = ::core::line!() as i32 + {body_offset} + 1;
{{ {{
#![allow(unreachable_pub)]
{body} {body}
main(); main();
}} }}