Add #[must_use] to len and is_empty
This commit is contained in:
parent
86d6d2b738
commit
6745e8da06
14 changed files with 62 additions and 42 deletions
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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>) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue