diff options
| author | John Kugelman <john@kugelman.name> | 2021-10-11 16:15:50 -0400 |
|---|---|---|
| committer | John Kugelman <john@kugelman.name> | 2021-10-30 19:25:12 -0400 |
| commit | 6745e8da06e1fd313d2ff20ff9fe8d8dc4714479 (patch) | |
| tree | 3e95126f0f29319c6c2ce80aef7fc275c1c33897 /library/alloc/src | |
| parent | 86d6d2b7389fe1b339402c1798edae8b695fc9ef (diff) | |
| download | rust-6745e8da06e1fd313d2ff20ff9fe8d8dc4714479.tar.gz rust-6745e8da06e1fd313d2ff20ff9fe8d8dc4714479.zip | |
Add #[must_use] to len and is_empty
Diffstat (limited to 'library/alloc/src')
| -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/set.rs | 2 | ||||
| -rw-r--r-- | library/alloc/src/collections/btree/set/tests.rs | 8 | ||||
| -rw-r--r-- | library/alloc/src/collections/linked_list.rs | 2 | ||||
| -rw-r--r-- | library/alloc/src/string.rs | 2 |
6 files changed, 14 insertions, 4 deletions
diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index 75720a970a3..5881f6227a0 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -1047,6 +1047,7 @@ impl<T> BinaryHeap<T> { /// /// assert_eq!(heap.len(), 2); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn len(&self) -> usize { self.data.len() @@ -1070,6 +1071,7 @@ impl<T> BinaryHeap<T> { /// /// assert!(!heap.is_empty()); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_empty(&self) -> bool { self.len() == 0 diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index e9265262c8b..a6ec5a83f14 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -2204,6 +2204,7 @@ impl<K, V> BTreeMap<K, V> { /// a.insert(1, "a"); /// assert_eq!(a.len(), 1); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_btree_new", issue = "71835")] pub const fn len(&self) -> usize { @@ -2224,6 +2225,7 @@ impl<K, V> BTreeMap<K, V> { /// a.insert(1, "a"); /// assert!(!a.is_empty()); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_btree_new", issue = "71835")] pub const fn is_empty(&self) -> bool { diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index f4c10100982..2ddebd416cb 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -1033,6 +1033,7 @@ impl<T> BTreeSet<T> { /// v.insert(1); /// assert_eq!(v.len(), 1); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_btree_new", issue = "71835")] pub const fn len(&self) -> usize { @@ -1051,6 +1052,7 @@ impl<T> BTreeSet<T> { /// v.insert(1); /// assert!(!v.is_empty()); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_btree_new", issue = "71835")] pub const fn is_empty(&self) -> bool { diff --git a/library/alloc/src/collections/btree/set/tests.rs b/library/alloc/src/collections/btree/set/tests.rs index 0a87ae12d61..2fc17a7c860 100644 --- a/library/alloc/src/collections/btree/set/tests.rs +++ b/library/alloc/src/collections/btree/set/tests.rs @@ -610,11 +610,11 @@ fn test_send() { #[test] fn test_ord_absence() { fn set<K>(mut set: BTreeSet<K>) { - set.is_empty(); - set.len(); + let _ = set.is_empty(); + let _ = set.len(); set.clear(); - set.iter(); - set.into_iter(); + let _ = set.iter(); + let _ = set.into_iter(); } fn set_debug<K: Debug>(set: BTreeSet<K>) { diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index a769c558b4f..bd00a56ac6e 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -576,6 +576,7 @@ impl<T> LinkedList<T> { /// assert!(!dl.is_empty()); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_empty(&self) -> bool { self.head.is_none() @@ -602,6 +603,7 @@ impl<T> LinkedList<T> { /// assert_eq!(dl.len(), 3); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn len(&self) -> usize { self.len diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index d00792b9c3e..651e55cc094 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -1537,6 +1537,7 @@ impl String { /// assert_eq!(fancy_f.chars().count(), 3); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn len(&self) -> usize { self.vec.len() @@ -1556,6 +1557,7 @@ impl String { /// assert!(!v.is_empty()); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_empty(&self) -> bool { self.len() == 0 |
