diff options
| author | bors <bors@rust-lang.org> | 2021-10-11 07:27:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-10-11 07:27:44 +0000 |
| commit | 86d6d2b7389fe1b339402c1798edae8b695fc9ef (patch) | |
| tree | 88c37951da1bbc2c46818b1705d6fa5e962eae5b /library/alloc | |
| parent | 9a757817c352801de8b0593728f8aee21e23cd53 (diff) | |
| parent | b115781bcd0609e94c08192924853097c73f1a1c (diff) | |
Auto merge of #89755 - jkugelman:must-use-conversions-that-move-self, r=joshtriplett
Add #[must_use] to conversions that move self Everything here got the same message. Is the wording okay? ```rust #[must_use = "`self` will be dropped if the result is not used"] ``` I want to draw attention to these methods in particular: ```rust alloc::sync::Arc<MaybeUninit<T>> unsafe fn assume_init(self) -> Arc<T>; alloc::sync::Arc<[MaybeUninit<T>]> unsafe fn assume_init(self) -> Arc<[T]>; core::pin::Pin<&'a mut T> const fn into_ref(self) -> Pin<&'a T>; core::pin::Pin<&'a mut T> const fn get_mut(self) -> &'a mut T; core::pin::Pin<&'a mut T> const unsafe fn get_unchecked_mut(self) -> &'a mut T; core::pin::Pin<&'a mut T> unsafe fn map_unchecked_mut(self, func: F) -> Pin<&'a mut U>; core::pin::Pin<&'a mut Pin<P>> fn as_deref_mut(self) -> Pin<&'a mut P::Target>; ``` Parent issue: #89692 r? `@joshtriplett`
Diffstat (limited to 'library/alloc')
| -rw-r--r-- | library/alloc/src/collections/binary_heap.rs | 2 | ||||
| -rw-r--r-- | library/alloc/src/collections/btree/map.rs | 2 | ||||
| -rw-r--r-- | library/alloc/src/collections/btree/map/entry.rs | 1 | ||||
| -rw-r--r-- | library/alloc/src/collections/btree/map/tests.rs | 20 | ||||
| -rw-r--r-- | library/alloc/src/rc.rs | 1 | ||||
| -rw-r--r-- | library/alloc/src/string.rs | 4 | ||||
| -rw-r--r-- | library/alloc/src/sync.rs | 3 |
7 files changed, 23 insertions, 10 deletions
diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index 4ed3702f7d2..75720a970a3 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -848,6 +848,7 @@ impl<T> BinaryHeap<T> { /// /// assert_eq!(heap.into_iter_sorted().take(2).collect::<Vec<_>>(), vec![5, 4]); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[unstable(feature = "binary_heap_into_iter_sorted", issue = "59278")] pub fn into_iter_sorted(self) -> IntoIterSorted<T> { IntoIterSorted { inner: self } @@ -1028,6 +1029,7 @@ impl<T> BinaryHeap<T> { /// println!("{}", x); /// } /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "binary_heap_extras_15", since = "1.5.0")] pub fn into_vec(self) -> Vec<T> { self.into() diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index d6032372168..e9265262c8b 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -1264,6 +1264,7 @@ impl<K, V> BTreeMap<K, V> { /// assert_eq!(keys, [1, 2]); /// ``` #[inline] + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "map_into_keys_values", since = "1.54.0")] pub fn into_keys(self) -> IntoKeys<K, V> { IntoKeys { inner: self.into_iter() } @@ -1286,6 +1287,7 @@ impl<K, V> BTreeMap<K, V> { /// assert_eq!(values, ["hello", "goodbye"]); /// ``` #[inline] + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "map_into_keys_values", since = "1.54.0")] pub fn into_values(self) -> IntoValues<K, V> { IntoValues { inner: self.into_iter() } diff --git a/library/alloc/src/collections/btree/map/entry.rs b/library/alloc/src/collections/btree/map/entry.rs index 5fec8dc2d13..3e9048b1768 100644 --- a/library/alloc/src/collections/btree/map/entry.rs +++ b/library/alloc/src/collections/btree/map/entry.rs @@ -448,6 +448,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> { /// } /// assert_eq!(map["poneyland"], 22); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "rust1", since = "1.0.0")] pub fn into_mut(self) -> &'a mut V { self.handle.into_val_mut() diff --git a/library/alloc/src/collections/btree/map/tests.rs b/library/alloc/src/collections/btree/map/tests.rs index b8e11e109c8..173960341f8 100644 --- a/library/alloc/src/collections/btree/map/tests.rs +++ b/library/alloc/src/collections/btree/map/tests.rs @@ -1755,20 +1755,20 @@ fn test_send() { #[test] fn test_ord_absence() { fn map<K>(mut map: BTreeMap<K, ()>) { - map.is_empty(); - map.len(); + let _ = map.is_empty(); + let _ = map.len(); map.clear(); - map.iter(); - map.iter_mut(); - map.keys(); - map.values(); - map.values_mut(); + let _ = map.iter(); + let _ = map.iter_mut(); + let _ = map.keys(); + let _ = map.values(); + let _ = map.values_mut(); if true { - map.into_values(); + let _ = map.into_values(); } else if true { - map.into_iter(); + let _ = map.into_iter(); } else { - map.into_keys(); + let _ = map.into_keys(); } } diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 81e97805a72..c6573597b1e 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -2130,6 +2130,7 @@ impl<T: ?Sized> Weak<T> { /// /// [`from_raw`]: Weak::from_raw /// [`as_ptr`]: Weak::as_ptr + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "weak_into_raw", since = "1.45.0")] pub fn into_raw(self) -> *const T { let result = self.as_ptr(); diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index d88b8e39898..d00792b9c3e 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -676,6 +676,7 @@ impl String { /// let rebuilt = unsafe { String::from_raw_parts(ptr, len, cap) }; /// assert_eq!(rebuilt, "hello"); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")] pub fn into_raw_parts(self) -> (*mut u8, usize, usize) { self.vec.into_raw_parts() @@ -781,6 +782,7 @@ impl String { /// assert_eq!(&[104, 101, 108, 108, 111][..], &bytes[..]); /// ``` #[inline] + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "rust1", since = "1.0.0")] pub fn into_bytes(self) -> Vec<u8> { self.vec @@ -1738,6 +1740,7 @@ impl String { /// ``` #[cfg(not(no_global_oom_handling))] #[stable(feature = "box_str", since = "1.4.0")] + #[must_use = "`self` will be dropped if the result is not used"] #[inline] pub fn into_boxed_str(self) -> Box<str> { let slice = self.vec.into_boxed_slice(); @@ -1783,6 +1786,7 @@ impl FromUtf8Error { /// /// assert_eq!(vec![0, 159], value.unwrap_err().into_bytes()); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "rust1", since = "1.0.0")] pub fn into_bytes(self) -> Vec<u8> { self.bytes diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 6e8da849e64..7dd1bc51560 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -735,6 +735,7 @@ impl<T> Arc<mem::MaybeUninit<T>> { /// assert_eq!(*five, 5) /// ``` #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use = "`self` will be dropped if the result is not used"] #[inline] pub unsafe fn assume_init(self) -> Arc<T> { Arc::from_inner(mem::ManuallyDrop::new(self).ptr.cast()) @@ -776,6 +777,7 @@ impl<T> Arc<[mem::MaybeUninit<T>]> { /// assert_eq!(*values, [1, 2, 3]) /// ``` #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use = "`self` will be dropped if the result is not used"] #[inline] pub unsafe fn assume_init(self) -> Arc<[T]> { unsafe { Arc::from_ptr(mem::ManuallyDrop::new(self).ptr.as_ptr() as _) } @@ -1759,6 +1761,7 @@ impl<T: ?Sized> Weak<T> { /// /// [`from_raw`]: Weak::from_raw /// [`as_ptr`]: Weak::as_ptr + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "weak_into_raw", since = "1.45.0")] pub fn into_raw(self) -> *const T { let result = self.as_ptr(); |
