Skip to content

Commit 68b554e

Browse files
committed
Auto merge of #90437 - matthiaskrgr:rollup-vd8uqm6, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #89068 (Restructure std::rt (part 2)) - #89786 (Add #[must_use] to len and is_empty) - #90430 (Add #[must_use] to remaining std functions (A-N)) - #90431 (Add #[must_use] to remaining std functions (O-Z)) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 58899c4 + 455a79a commit 68b554e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+198
-72
lines changed

library/alloc/src/collections/binary_heap.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,7 @@ impl<T> BinaryHeap<T> {
10521052
///
10531053
/// assert_eq!(heap.len(), 2);
10541054
/// ```
1055+
#[must_use]
10551056
#[stable(feature = "rust1", since = "1.0.0")]
10561057
pub fn len(&self) -> usize {
10571058
self.data.len()
@@ -1075,6 +1076,7 @@ impl<T> BinaryHeap<T> {
10751076
///
10761077
/// assert!(!heap.is_empty());
10771078
/// ```
1079+
#[must_use]
10781080
#[stable(feature = "rust1", since = "1.0.0")]
10791081
pub fn is_empty(&self) -> bool {
10801082
self.len() == 0

library/alloc/src/collections/btree/map.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,7 @@ impl<K, V> BTreeMap<K, V> {
22122212
/// a.insert(1, "a");
22132213
/// assert_eq!(a.len(), 1);
22142214
/// ```
2215+
#[must_use]
22152216
#[stable(feature = "rust1", since = "1.0.0")]
22162217
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
22172218
pub const fn len(&self) -> usize {
@@ -2232,6 +2233,7 @@ impl<K, V> BTreeMap<K, V> {
22322233
/// a.insert(1, "a");
22332234
/// assert!(!a.is_empty());
22342235
/// ```
2236+
#[must_use]
22352237
#[stable(feature = "rust1", since = "1.0.0")]
22362238
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
22372239
pub const fn is_empty(&self) -> bool {

library/alloc/src/collections/btree/set.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ impl<T> BTreeSet<T> {
10461046
/// v.insert(1);
10471047
/// assert_eq!(v.len(), 1);
10481048
/// ```
1049+
#[must_use]
10491050
#[stable(feature = "rust1", since = "1.0.0")]
10501051
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
10511052
pub const fn len(&self) -> usize {
@@ -1064,6 +1065,7 @@ impl<T> BTreeSet<T> {
10641065
/// v.insert(1);
10651066
/// assert!(!v.is_empty());
10661067
/// ```
1068+
#[must_use]
10671069
#[stable(feature = "rust1", since = "1.0.0")]
10681070
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
10691071
pub const fn is_empty(&self) -> bool {

library/alloc/src/collections/btree/set/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,8 @@ fn test_send() {
610610
#[test]
611611
fn test_ord_absence() {
612612
fn set<K>(mut set: BTreeSet<K>) {
613-
set.is_empty();
614-
set.len();
613+
let _ = set.is_empty();
614+
let _ = set.len();
615615
set.clear();
616616
let _ = set.iter();
617617
let _ = set.into_iter();

library/alloc/src/collections/linked_list.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ impl<T> LinkedList<T> {
583583
/// assert!(!dl.is_empty());
584584
/// ```
585585
#[inline]
586+
#[must_use]
586587
#[stable(feature = "rust1", since = "1.0.0")]
587588
pub fn is_empty(&self) -> bool {
588589
self.head.is_none()
@@ -609,6 +610,7 @@ impl<T> LinkedList<T> {
609610
/// assert_eq!(dl.len(), 3);
610611
/// ```
611612
#[inline]
613+
#[must_use]
612614
#[stable(feature = "rust1", since = "1.0.0")]
613615
pub fn len(&self) -> usize {
614616
self.len

library/alloc/src/string.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,7 @@ impl String {
15471547
/// assert_eq!(fancy_f.chars().count(), 3);
15481548
/// ```
15491549
#[inline]
1550+
#[must_use]
15501551
#[stable(feature = "rust1", since = "1.0.0")]
15511552
pub fn len(&self) -> usize {
15521553
self.vec.len()
@@ -1566,6 +1567,7 @@ impl String {
15661567
/// assert!(!v.is_empty());
15671568
/// ```
15681569
#[inline]
1570+
#[must_use]
15691571
#[stable(feature = "rust1", since = "1.0.0")]
15701572
pub fn is_empty(&self) -> bool {
15711573
self.len() == 0

library/core/src/ptr/non_null.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ impl<T> NonNull<[T]> {
449449
/// ```
450450
#[unstable(feature = "slice_ptr_len", issue = "71146")]
451451
#[rustc_const_unstable(feature = "const_slice_ptr_len", issue = "71146")]
452+
#[must_use]
452453
#[inline]
453454
pub const fn len(self) -> usize {
454455
self.as_ptr().len()

library/core/src/str/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ impl str {
140140
/// ```
141141
#[stable(feature = "rust1", since = "1.0.0")]
142142
#[rustc_const_stable(feature = "const_str_len", since = "1.39.0")]
143+
#[must_use]
143144
#[inline]
144145
pub const fn len(&self) -> usize {
145146
self.as_bytes().len()
@@ -158,9 +159,10 @@ impl str {
158159
/// let s = "not empty";
159160
/// assert!(!s.is_empty());
160161
/// ```
161-
#[inline]
162162
#[stable(feature = "rust1", since = "1.0.0")]
163163
#[rustc_const_stable(feature = "const_str_is_empty", since = "1.39.0")]
164+
#[must_use]
165+
#[inline]
164166
pub const fn is_empty(&self) -> bool {
165167
self.len() == 0
166168
}

library/std/src/backtrace.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ use crate::vec::Vec;
110110
/// previous point in time. In some instances the `Backtrace` type may
111111
/// internally be empty due to configuration. For more information see
112112
/// `Backtrace::capture`.
113+
#[must_use]
113114
pub struct Backtrace {
114115
inner: Inner,
115116
}
@@ -355,6 +356,7 @@ impl Backtrace {
355356
/// Returns the status of this backtrace, indicating whether this backtrace
356357
/// request was unsupported, disabled, or a stack trace was actually
357358
/// captured.
359+
#[must_use]
358360
pub fn status(&self) -> BacktraceStatus {
359361
match self.inner {
360362
Inner::Unsupported => BacktraceStatus::Unsupported,
@@ -366,6 +368,7 @@ impl Backtrace {
366368

367369
impl<'a> Backtrace {
368370
/// Returns an iterator over the backtrace frames.
371+
#[must_use]
369372
#[unstable(feature = "backtrace_frames", issue = "79676")]
370373
pub fn frames(&'a self) -> &'a [BacktraceFrame] {
371374
if let Inner::Captured(c) = &self.inner { &c.force().frames } else { &[] }

library/std/src/collections/hash/map.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,13 +1707,15 @@ impl<'a, K, V, S> RawEntryMut<'a, K, V, S> {
17071707
impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {
17081708
/// Gets a reference to the key in the entry.
17091709
#[inline]
1710+
#[must_use]
17101711
#[unstable(feature = "hash_raw_entry", issue = "56167")]
17111712
pub fn key(&self) -> &K {
17121713
self.base.key()
17131714
}
17141715

17151716
/// Gets a mutable reference to the key in the entry.
17161717
#[inline]
1718+
#[must_use]
17171719
#[unstable(feature = "hash_raw_entry", issue = "56167")]
17181720
pub fn key_mut(&mut self) -> &mut K {
17191721
self.base.key_mut()
@@ -1730,6 +1732,7 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {
17301732

17311733
/// Gets a reference to the value in the entry.
17321734
#[inline]
1735+
#[must_use]
17331736
#[unstable(feature = "hash_raw_entry", issue = "56167")]
17341737
pub fn get(&self) -> &V {
17351738
self.base.get()
@@ -1746,13 +1749,15 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {
17461749

17471750
/// Gets a mutable reference to the value in the entry.
17481751
#[inline]
1752+
#[must_use]
17491753
#[unstable(feature = "hash_raw_entry", issue = "56167")]
17501754
pub fn get_mut(&mut self) -> &mut V {
17511755
self.base.get_mut()
17521756
}
17531757

17541758
/// Gets a reference to the key and value in the entry.
17551759
#[inline]
1760+
#[must_use]
17561761
#[unstable(feature = "hash_raw_entry", issue = "56167")]
17571762
pub fn get_key_value(&mut self) -> (&K, &V) {
17581763
self.base.get_key_value()

0 commit comments

Comments
 (0)