Skip to content

Commit d187f0b

Browse files
ojedafbq
authored andcommitted
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> Link: https://lore.kernel.org/r/20230718052752.1045248-5-ojeda@kernel.org
1 parent 4bc4ab9 commit d187f0b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

rust/kernel/sync/arc.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ mod std_vendor;
7373
/// assert_eq!(cloned.b, 20);
7474
///
7575
/// // The refcount drops to zero when `cloned` goes out of scope, and the memory is freed.
76+
/// # Ok::<(), Error>(())
7677
/// ```
7778
///
7879
/// Using `Arc<T>` as the type of `self`:
@@ -98,6 +99,7 @@ mod std_vendor;
9899
/// let obj = Arc::try_new(Example { a: 10, b: 20 })?;
99100
/// obj.use_reference();
100101
/// obj.take_over();
102+
/// # Ok::<(), Error>(())
101103
/// ```
102104
///
103105
/// Coercion from `Arc<Example>` to `Arc<dyn MyTrait>`:
@@ -121,6 +123,7 @@ mod std_vendor;
121123
///
122124
/// // `coerced` has type `Arc<dyn MyTrait>`.
123125
/// let coerced: Arc<dyn MyTrait> = obj;
126+
/// # Ok::<(), Error>(())
124127
/// ```
125128
pub struct Arc<T: ?Sized> {
126129
ptr: NonNull<ArcInner<T>>,
@@ -336,7 +339,7 @@ impl<T: ?Sized> From<Pin<UniqueArc<T>>> for Arc<T> {
336339
/// # Example
337340
///
338341
/// ```
339-
/// use crate::sync::{Arc, ArcBorrow};
342+
/// use kernel::sync::{Arc, ArcBorrow};
340343
///
341344
/// struct Example;
342345
///
@@ -349,12 +352,13 @@ impl<T: ?Sized> From<Pin<UniqueArc<T>>> for Arc<T> {
349352
///
350353
/// // Assert that both `obj` and `cloned` point to the same underlying object.
351354
/// assert!(core::ptr::eq(&*obj, &*cloned));
355+
/// # Ok::<(), Error>(())
352356
/// ```
353357
///
354358
/// Using `ArcBorrow<T>` as the type of `self`:
355359
///
356360
/// ```
357-
/// use crate::sync::{Arc, ArcBorrow};
361+
/// use kernel::sync::{Arc, ArcBorrow};
358362
///
359363
/// struct Example {
360364
/// a: u32,
@@ -369,6 +373,7 @@ impl<T: ?Sized> From<Pin<UniqueArc<T>>> for Arc<T> {
369373
///
370374
/// let obj = Arc::try_new(Example { a: 10, b: 20 })?;
371375
/// obj.as_arc_borrow().use_reference();
376+
/// # Ok::<(), Error>(())
372377
/// ```
373378
pub struct ArcBorrow<'a, T: ?Sized + 'a> {
374379
inner: NonNull<ArcInner<T>>,

rust/kernel/sync/lock/mutex.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ macro_rules! new_mutex {
6363
/// assert_eq!(e.c, 10);
6464
/// assert_eq!(e.d.lock().a, 20);
6565
/// assert_eq!(e.d.lock().b, 30);
66+
/// # Ok::<(), Error>(())
6667
/// ```
6768
///
6869
/// The following example shows how to use interior mutability to modify the contents of a struct

rust/kernel/sync/lock/spinlock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ macro_rules! new_spinlock {
6161
/// assert_eq!(e.c, 10);
6262
/// assert_eq!(e.d.lock().a, 20);
6363
/// assert_eq!(e.d.lock().b, 30);
64+
/// # Ok::<(), Error>(())
6465
/// ```
6566
///
6667
/// The following example shows how to use interior mutability to modify the contents of a struct

0 commit comments

Comments
 (0)