about summary refs log tree commit diff
path: root/library/core
diff options
context:
space:
mode:
authorJohn Kugelman <john@kugelman.name>2021-10-11 16:15:50 -0400
committerJohn Kugelman <john@kugelman.name>2021-10-30 19:25:12 -0400
commit6745e8da06e1fd313d2ff20ff9fe8d8dc4714479 (patch)
tree3e95126f0f29319c6c2ce80aef7fc275c1c33897 /library/core
parent86d6d2b7389fe1b339402c1798edae8b695fc9ef (diff)
downloadrust-6745e8da06e1fd313d2ff20ff9fe8d8dc4714479.tar.gz
rust-6745e8da06e1fd313d2ff20ff9fe8d8dc4714479.zip
Add #[must_use] to len and is_empty
Diffstat (limited to 'library/core')
-rw-r--r--library/core/src/ptr/non_null.rs1
-rw-r--r--library/core/src/str/mod.rs4
2 files changed, 4 insertions, 1 deletions
diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs
index 87c8674af0d..1821954edd5 100644
--- a/library/core/src/ptr/non_null.rs
+++ b/library/core/src/ptr/non_null.rs
@@ -438,6 +438,7 @@ impl<T> NonNull<[T]> {
     /// ```
     #[unstable(feature = "slice_ptr_len", issue = "71146")]
     #[rustc_const_unstable(feature = "const_slice_ptr_len", issue = "71146")]
+    #[must_use]
     #[inline]
     pub const fn len(self) -> usize {
         self.as_ptr().len()
diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs
index 14ce94c178c..a6ba019f368 100644
--- a/library/core/src/str/mod.rs
+++ b/library/core/src/str/mod.rs
@@ -140,6 +140,7 @@ impl str {
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     #[rustc_const_stable(feature = "const_str_len", since = "1.39.0")]
+    #[must_use]
     #[inline]
     pub const fn len(&self) -> usize {
         self.as_bytes().len()
@@ -158,9 +159,10 @@ impl str {
     /// let s = "not empty";
     /// assert!(!s.is_empty());
     /// ```
-    #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
     #[rustc_const_stable(feature = "const_str_is_empty", since = "1.39.0")]
+    #[must_use]
+    #[inline]
     pub const fn is_empty(&self) -> bool {
         self.len() == 0
     }