Rollup merge of #89786 - jkugelman:must-use-len-and-is_empty, r=joshtriplett
Add #[must_use] to len and is_empty Parent issue: #89692 r? `@joshtriplett`
This commit is contained in:
commit
88e5ae2dd3
14 changed files with 60 additions and 40 deletions
|
@ -1052,6 +1052,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()
|
||||
|
@ -1075,6 +1076,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
|
||||
|
|
|
@ -2212,6 +2212,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 {
|
||||
|
@ -2232,6 +2233,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 {
|
||||
|
|
|
@ -1046,6 +1046,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 {
|
||||
|
@ -1064,6 +1065,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,8 +610,8 @@ 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();
|
||||
let _ = set.iter();
|
||||
let _ = set.into_iter();
|
||||
|
|
|
@ -583,6 +583,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()
|
||||
|
@ -609,6 +610,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
|
||||
|
|
|
@ -1547,6 +1547,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()
|
||||
|
@ -1566,6 +1567,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