Skip to content

Commit ab844cf

Browse files
committed
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>
1 parent bf724be commit ab844cf

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

rust/kernel/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
//! ```
6868
//!
6969
//! ```rust
70-
//! # #![expect(unreachable_pub, clippy::disallowed_names)]
70+
//! # #![expect(clippy::disallowed_names)]
7171
//! use kernel::{prelude::*, types::Opaque};
7272
//! use core::{ptr::addr_of_mut, marker::PhantomPinned, pin::Pin};
7373
//! # mod bindings {

rust/kernel/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl<T, F: FnOnce(T)> Drop for ScopeGuard<T, F> {
289289
/// # Examples
290290
///
291291
/// ```
292-
/// # #![expect(unreachable_pub, clippy::disallowed_names)]
292+
/// # #![expect(clippy::disallowed_names)]
293293
/// use kernel::types::Opaque;
294294
/// # // Emulate a C struct binding which is from C, maybe uninitialized or not, only the C side
295295
/// # // knows.

scripts/rustdoc_test_gen.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ pub extern "C" fn {kunit_name}(__kunit_test: *mut ::kernel::bindings::kunit) {{
208208
#[allow(unused)]
209209
static __DOCTEST_ANCHOR: i32 = ::core::line!() as i32 + {body_offset} + 1;
210210
{{
211+
#![allow(unreachable_pub)]
211212
{body}
212213
main();
213214
}}

0 commit comments

Comments
 (0)