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

rust: sync: 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: Björn Roy Baron <bjorn3_gh@protonmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: David Gow <davidgow@google.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
bfa7dff0 cf36a495

+9 -2
+7 -2
rust/kernel/sync/arc.rs
··· 73 73 /// assert_eq!(cloned.b, 20); 74 74 /// 75 75 /// // The refcount drops to zero when `cloned` goes out of scope, and the memory is freed. 76 + /// # Ok::<(), Error>(()) 76 77 /// ``` 77 78 /// 78 79 /// Using `Arc<T>` as the type of `self`: ··· 99 98 /// let obj = Arc::try_new(Example { a: 10, b: 20 })?; 100 99 /// obj.use_reference(); 101 100 /// obj.take_over(); 101 + /// # Ok::<(), Error>(()) 102 102 /// ``` 103 103 /// 104 104 /// Coercion from `Arc<Example>` to `Arc<dyn MyTrait>`: ··· 123 121 /// 124 122 /// // `coerced` has type `Arc<dyn MyTrait>`. 125 123 /// let coerced: Arc<dyn MyTrait> = obj; 124 + /// # Ok::<(), Error>(()) 126 125 /// ``` 127 126 pub struct Arc<T: ?Sized> { 128 127 ptr: NonNull<ArcInner<T>>, ··· 340 337 /// # Example 341 338 /// 342 339 /// ``` 343 - /// use crate::sync::{Arc, ArcBorrow}; 340 + /// use kernel::sync::{Arc, ArcBorrow}; 344 341 /// 345 342 /// struct Example; 346 343 /// ··· 353 350 /// 354 351 /// // Assert that both `obj` and `cloned` point to the same underlying object. 355 352 /// assert!(core::ptr::eq(&*obj, &*cloned)); 353 + /// # Ok::<(), Error>(()) 356 354 /// ``` 357 355 /// 358 356 /// Using `ArcBorrow<T>` as the type of `self`: 359 357 /// 360 358 /// ``` 361 - /// use crate::sync::{Arc, ArcBorrow}; 359 + /// use kernel::sync::{Arc, ArcBorrow}; 362 360 /// 363 361 /// struct Example { 364 362 /// a: u32, ··· 374 370 /// 375 371 /// let obj = Arc::try_new(Example { a: 10, b: 20 })?; 376 372 /// obj.as_arc_borrow().use_reference(); 373 + /// # Ok::<(), Error>(()) 377 374 /// ``` 378 375 pub struct ArcBorrow<'a, T: ?Sized + 'a> { 379 376 inner: NonNull<ArcInner<T>>,
+1
rust/kernel/sync/lock/mutex.rs
··· 63 63 /// assert_eq!(e.c, 10); 64 64 /// assert_eq!(e.d.lock().a, 20); 65 65 /// assert_eq!(e.d.lock().b, 30); 66 + /// # Ok::<(), Error>(()) 66 67 /// ``` 67 68 /// 68 69 /// The following example shows how to use interior mutability to modify the contents of a struct
+1
rust/kernel/sync/lock/spinlock.rs
··· 61 61 /// assert_eq!(e.c, 10); 62 62 /// assert_eq!(e.d.lock().a, 20); 63 63 /// assert_eq!(e.d.lock().b, 30); 64 + /// # Ok::<(), Error>(()) 64 65 /// ``` 65 66 /// 66 67 /// The following example shows how to use interior mutability to modify the contents of a struct