Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: init: make doctests compilable/testable

Rust documentation tests are going to be build/run-tested
with the KUnit integration added in a future patch, thus
update them to make them compilable/testable so that we
may start enforcing it.

Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Reviewed-by: David Gow <davidgow@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Björn Roy Baron <bjorn3_gh@protonmail.com>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Miguel Ojeda and committed by
Shuah Khan
a30e94c2 df3cb7ac

+17 -9
+17 -9
rust/kernel/init.rs
··· 120 120 //! `slot` gets called. 121 121 //! 122 122 //! ```rust 123 - //! use kernel::{prelude::*, init}; 123 + //! # #![allow(unreachable_pub, clippy::disallowed_names)] 124 + //! use kernel::{prelude::*, init, types::Opaque}; 124 125 //! use core::{ptr::addr_of_mut, marker::PhantomPinned, pin::Pin}; 125 126 //! # mod bindings { 127 + //! # #![allow(non_camel_case_types)] 126 128 //! # pub struct foo; 127 129 //! # pub unsafe fn init_foo(_ptr: *mut foo) {} 128 130 //! # pub unsafe fn destroy_foo(_ptr: *mut foo) {} 129 131 //! # pub unsafe fn enable_foo(_ptr: *mut foo, _flags: u32) -> i32 { 0 } 130 132 //! # } 133 + //! # // `Error::from_errno` is `pub(crate)` in the `kernel` crate, thus provide a workaround. 134 + //! # trait FromErrno { 135 + //! # fn from_errno(errno: core::ffi::c_int) -> Error { 136 + //! # // Dummy error that can be constructed outside the `kernel` crate. 137 + //! # Error::from(core::fmt::Error) 138 + //! # } 139 + //! # } 140 + //! # impl FromErrno for Error {} 131 141 //! /// # Invariants 132 142 //! /// 133 143 //! /// `foo` is always initialized ··· 168 158 //! if err != 0 { 169 159 //! // Enabling has failed, first clean up the foo and then return the error. 170 160 //! bindings::destroy_foo(Opaque::raw_get(foo)); 171 - //! return Err(Error::from_kernel_errno(err)); 161 + //! return Err(Error::from_errno(err)); 172 162 //! } 173 163 //! 174 164 //! // All fields of `RawFoo` have been initialized, since `_p` is a ZST. ··· 236 226 /// 237 227 /// ```rust 238 228 /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] 239 - /// # use kernel::{init, pin_init, stack_pin_init, init::*, sync::Mutex, new_mutex}; 240 - /// # use macros::pin_data; 229 + /// # use kernel::{init, macros::pin_data, pin_init, stack_pin_init, init::*, sync::Mutex, new_mutex}; 241 230 /// # use core::pin::Pin; 242 231 /// #[pin_data] 243 232 /// struct Foo { ··· 286 277 /// 287 278 /// # Examples 288 279 /// 289 - /// ```rust 280 + /// ```rust,ignore 290 281 /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] 291 282 /// # use kernel::{init, pin_init, stack_try_pin_init, init::*, sync::Mutex, new_mutex}; 292 283 /// # use macros::pin_data; ··· 312 303 /// pr_info!("a: {}", &*foo.a.lock()); 313 304 /// ``` 314 305 /// 315 - /// ```rust 306 + /// ```rust,ignore 316 307 /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] 317 308 /// # use kernel::{init, pin_init, stack_try_pin_init, init::*, sync::Mutex, new_mutex}; 318 309 /// # use macros::pin_data; ··· 522 513 /// For instance: 523 514 /// 524 515 /// ```rust 525 - /// # use kernel::pin_init; 526 - /// # use macros::pin_data; 516 + /// # use kernel::{macros::pin_data, pin_init}; 527 517 /// # use core::{ptr::addr_of_mut, marker::PhantomPinned}; 528 518 /// #[pin_data] 529 519 /// struct Buf { ··· 849 841 /// # Examples 850 842 /// 851 843 /// ```rust 852 - /// use kernel::{init::PinInit, error::Error, InPlaceInit}; 844 + /// use kernel::{init::{PinInit, zeroed}, error::Error}; 853 845 /// struct BigBuf { 854 846 /// big: Box<[u8; 1024 * 1024 * 1024]>, 855 847 /// small: [u8; 1024 * 1024],