From c3f0577002b5c158c63dab92476d94af954086f1 Mon Sep 17 00:00:00 2001 From: John Kugelman Date: Mon, 11 Oct 2021 20:40:03 -0400 Subject: Add #[must_use] to non-mutating verb methods --- library/alloc/src/rc.rs | 2 ++ library/alloc/src/sync.rs | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'library/alloc') diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 2f4a131136e..4023d7b21ed 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -2229,6 +2229,8 @@ impl Weak { /// /// assert!(weak_five.upgrade().is_none()); /// ``` + #[must_use = "this returns a new `Rc`, \ + without modifying the original weak pointer"] #[stable(feature = "rc_weak", since = "1.4.0")] pub fn upgrade(&self) -> Option> { let inner = self.inner()?; diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 1d4216d7d57..905e3d72a45 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -146,7 +146,7 @@ macro_rules! acquire { /// use std::sync::Arc; /// /// let my_arc = Arc::new(()); -/// Arc::downgrade(&my_arc); +/// let my_weak = Arc::downgrade(&my_arc); /// ``` /// /// `Arc`'s implementations of traits like `Clone` may also be called using @@ -897,6 +897,8 @@ impl Arc { /// /// let weak_five = Arc::downgrade(&five); /// ``` + #[must_use = "this returns a new `Weak` pointer, \ + without modifying the original `Arc`"] #[stable(feature = "arc_weak", since = "1.4.0")] pub fn downgrade(this: &Self) -> Weak { // This Relaxed is OK because we're checking the value in the CAS @@ -1861,6 +1863,8 @@ impl Weak { /// /// assert!(weak_five.upgrade().is_none()); /// ``` + #[must_use = "this returns a new `Arc`, \ + without modifying the original weak pointer"] #[stable(feature = "arc_weak", since = "1.4.0")] pub fn upgrade(&self) -> Option> { // We use a CAS loop to increment the strong count instead of a -- cgit 1.4.1-3-g733a5