From 457aa3394238fc4069d724a5ee74bd61d29c8da9 Mon Sep 17 00:00:00 2001 From: Matthew Ahrens Date: Fri, 11 Mar 2022 18:28:31 -0800 Subject: [PATCH] fix doctest (#287) `cargo test` runs both the explicit tests and any code in doc comments that is not explicitly ignored. There are some failures in lazy_static_ptr.rs and vec_ext.rs, which this commit fixes by making the example code actually runnable. --- .../util/src/lazy_static_ptr.rs | 19 +++++++++---------- cmd/zfs_object_agent/util/src/vec_ext.rs | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cmd/zfs_object_agent/util/src/lazy_static_ptr.rs b/cmd/zfs_object_agent/util/src/lazy_static_ptr.rs index 15d28156a8cc..d59c345e236b 100644 --- a/cmd/zfs_object_agent/util/src/lazy_static_ptr.rs +++ b/cmd/zfs_object_agent/util/src/lazy_static_ptr.rs @@ -18,13 +18,13 @@ pub use paste::paste; /// /// For example: /// ``` -/// lazy_static_ptr! { -/// pub static ref STRINGS: Mutex> = Default::default(); +/// util::lazy_static_ptr! { +/// pub static ref STRINGS: std::sync::Mutex> = Default::default(); /// } /// ``` /// This will declare a `pub static` variable named `STRINGS` which will deref to a /// `Box>>`, similar to lazy_static!. Additionally, it will declare -/// ``` +/// ```ignore /// static STRINGS_PTR: AtomicPtr>> = ...; /// ``` /// When `STRINGS` is initialized (on first dereference, or the .initialize() method), @@ -127,14 +127,13 @@ impl Drop for DebugPointerGuard { /// we are storing (but not dereferencing) a pointer to it. Typical use is combined with /// `lazy_static_ptr!`: /// ``` -/// fn func(thing: Thing) { -/// lazy_static_ptr! { -/// static ref THINGS: DebugPointerSet = Default::default(); -/// } -/// let mut thing = THINGS.insert(thing); -/// // use `thing` as usual, it deref's to the passed in Thing -/// thing.method(); +/// use util::lazy_static_ptr::DebugPointerSet; +/// util::lazy_static_ptr! { +/// static ref THINGS: DebugPointerSet> = Default::default(); /// } +/// let mut thing = THINGS.insert(Default::default()); +/// // use `thing` as usual, it deref's to the passed in Thing +/// thing.push(42); /// ``` /// Note that `lazy_static_ptr!` doesn't work well inside `async` /// functions/methods/closures, because it's hard to name the variable in the diff --git a/cmd/zfs_object_agent/util/src/vec_ext.rs b/cmd/zfs_object_agent/util/src/vec_ext.rs index 5bb945f23c47..d13f16af5138 100644 --- a/cmd/zfs_object_agent/util/src/vec_ext.rs +++ b/cmd/zfs_object_agent/util/src/vec_ext.rs @@ -12,7 +12,7 @@ use more_asserts::*; /// #[derivative(Debug)] /// struct Foo { /// #[derivative(Debug(format_with = "util::tersevec"))] -/// member: Vec +/// member: Vec /// } /// ``` pub fn tersevec(vec: &[E], fmt: &mut Formatter) -> Result {