Skip to content

Commit c3f0577

Browse files
committed
Add #[must_use] to non-mutating verb methods
1 parent 5b21064 commit c3f0577

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

library/alloc/src/rc.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2229,6 +2229,8 @@ impl<T: ?Sized> Weak<T> {
22292229
///
22302230
/// assert!(weak_five.upgrade().is_none());
22312231
/// ```
2232+
#[must_use = "this returns a new `Rc`, \
2233+
without modifying the original weak pointer"]
22322234
#[stable(feature = "rc_weak", since = "1.4.0")]
22332235
pub fn upgrade(&self) -> Option<Rc<T>> {
22342236
let inner = self.inner()?;

library/alloc/src/sync.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ macro_rules! acquire {
146146
/// use std::sync::Arc;
147147
///
148148
/// let my_arc = Arc::new(());
149-
/// Arc::downgrade(&my_arc);
149+
/// let my_weak = Arc::downgrade(&my_arc);
150150
/// ```
151151
///
152152
/// `Arc<T>`'s implementations of traits like `Clone` may also be called using
@@ -897,6 +897,8 @@ impl<T: ?Sized> Arc<T> {
897897
///
898898
/// let weak_five = Arc::downgrade(&five);
899899
/// ```
900+
#[must_use = "this returns a new `Weak` pointer, \
901+
without modifying the original `Arc`"]
900902
#[stable(feature = "arc_weak", since = "1.4.0")]
901903
pub fn downgrade(this: &Self) -> Weak<T> {
902904
// This Relaxed is OK because we're checking the value in the CAS
@@ -1861,6 +1863,8 @@ impl<T: ?Sized> Weak<T> {
18611863
///
18621864
/// assert!(weak_five.upgrade().is_none());
18631865
/// ```
1866+
#[must_use = "this returns a new `Arc`, \
1867+
without modifying the original weak pointer"]
18641868
#[stable(feature = "arc_weak", since = "1.4.0")]
18651869
pub fn upgrade(&self) -> Option<Arc<T>> {
18661870
// We use a CAS loop to increment the strong count instead of a

library/core/src/alloc/layout.rs

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ impl Layout {
112112
/// The minimum byte alignment for a memory block of this layout.
113113
#[stable(feature = "alloc_layout", since = "1.28.0")]
114114
#[rustc_const_stable(feature = "const_alloc_layout", since = "1.50.0")]
115+
#[must_use = "this returns the minimum alignment, \
116+
without modifying the layout"]
115117
#[inline]
116118
pub const fn align(&self) -> usize {
117119
self.align_.get()
@@ -229,6 +231,8 @@ impl Layout {
229231
/// satisfy this constraint is to ensure `align <= self.align()`.
230232
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
231233
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
234+
#[must_use = "this returns the padding needed, \
235+
without modifying the `Layout`"]
232236
#[inline]
233237
pub const fn padding_needed_for(&self, align: usize) -> usize {
234238
let len = self.size();
@@ -262,6 +266,8 @@ impl Layout {
262266
/// This is equivalent to adding the result of `padding_needed_for`
263267
/// to the layout's current size.
264268
#[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
269+
#[must_use = "this returns a new `Layout`, \
270+
without modifying the original"]
265271
#[inline]
266272
pub fn pad_to_align(&self) -> Layout {
267273
let pad = self.padding_needed_for(self.align());

library/std/src/path.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,8 @@ impl Path {
25112511
/// println!("{}", path.display());
25122512
/// ```
25132513
#[stable(feature = "rust1", since = "1.0.0")]
2514+
#[must_use = "this does not display the path, \
2515+
it returns an object that can be displayed"]
25142516
#[inline]
25152517
pub fn display(&self) -> Display<'_> {
25162518
Display { path: self }

0 commit comments

Comments
 (0)