Add #[must_use] to remaining alloc functions
This commit is contained in:
parent
e1e9319d93
commit
fb2d0f5c03
@ -290,7 +290,7 @@ where
|
||||
let mut c = 0;
|
||||
for i in 0..BENCH_RANGE_SIZE {
|
||||
for j in i + 1..BENCH_RANGE_SIZE {
|
||||
black_box(map.range(f(i, j)));
|
||||
let _ = black_box(map.range(f(i, j)));
|
||||
c += 1;
|
||||
}
|
||||
}
|
||||
@ -322,7 +322,7 @@ fn bench_iter(b: &mut Bencher, repeats: i32, size: i32) {
|
||||
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
|
||||
b.iter(|| {
|
||||
for _ in 0..repeats {
|
||||
black_box(map.iter());
|
||||
let _ = black_box(map.iter());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -512,6 +512,7 @@ impl<T: Ord> BinaryHeap<T> {
|
||||
/// let vec = heap.into_sorted_vec();
|
||||
/// assert_eq!(vec, [1, 2, 3, 4, 5, 6, 7]);
|
||||
/// ```
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[stable(feature = "binary_heap_extras_15", since = "1.5.0")]
|
||||
pub fn into_sorted_vec(mut self) -> Vec<T> {
|
||||
let mut end = self.len();
|
||||
@ -850,7 +851,6 @@ impl<T> BinaryHeap<T> {
|
||||
///
|
||||
/// assert_eq!(heap.into_iter_sorted().take(2).collect::<Vec<_>>(), vec![5, 4]);
|
||||
/// ```
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[unstable(feature = "binary_heap_into_iter_sorted", issue = "59278")]
|
||||
pub fn into_iter_sorted(self) -> IntoIterSorted<T> {
|
||||
IntoIterSorted { inner: self }
|
||||
@ -877,6 +877,7 @@ impl<T> BinaryHeap<T> {
|
||||
/// # Time complexity
|
||||
///
|
||||
/// Cost is *O*(1) in the worst case.
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn peek(&self) -> Option<&T> {
|
||||
self.data.get(0)
|
||||
@ -894,6 +895,7 @@ impl<T> BinaryHeap<T> {
|
||||
/// assert!(heap.capacity() >= 100);
|
||||
/// heap.push(4);
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn capacity(&self) -> usize {
|
||||
self.data.capacity()
|
||||
@ -1203,6 +1205,7 @@ impl<T> Drop for Hole<'_, T> {
|
||||
/// documentation for more.
|
||||
///
|
||||
/// [`iter`]: BinaryHeap::iter
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Iter<'a, T: 'a> {
|
||||
iter: slice::Iter<'a, T>,
|
||||
@ -1337,6 +1340,7 @@ impl<I> AsIntoIter for IntoIter<I> {
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[unstable(feature = "binary_heap_into_iter_sorted", issue = "59278")]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct IntoIterSorted<T> {
|
||||
|
@ -288,6 +288,7 @@ where
|
||||
/// documentation for more.
|
||||
///
|
||||
/// [`iter`]: BTreeMap::iter
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Iter<'a, K: 'a, V: 'a> {
|
||||
range: LazyLeafRange<marker::Immut<'a>, K, V>,
|
||||
@ -316,6 +317,7 @@ pub struct IterMut<'a, K: 'a, V: 'a> {
|
||||
_marker: PhantomData<&'a mut (K, V)>,
|
||||
}
|
||||
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "collection_debug", since = "1.17.0")]
|
||||
impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for IterMut<'_, K, V> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
@ -359,6 +361,7 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for IntoIter<K, V> {
|
||||
/// documentation for more.
|
||||
///
|
||||
/// [`keys`]: BTreeMap::keys
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Keys<'a, K: 'a, V: 'a> {
|
||||
inner: Iter<'a, K, V>,
|
||||
@ -377,6 +380,7 @@ impl<K: fmt::Debug, V> fmt::Debug for Keys<'_, K, V> {
|
||||
/// documentation for more.
|
||||
///
|
||||
/// [`values`]: BTreeMap::values
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Values<'a, K: 'a, V: 'a> {
|
||||
inner: Iter<'a, K, V>,
|
||||
@ -395,6 +399,7 @@ impl<K, V: fmt::Debug> fmt::Debug for Values<'_, K, V> {
|
||||
/// documentation for more.
|
||||
///
|
||||
/// [`values_mut`]: BTreeMap::values_mut
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "map_values_mut", since = "1.10.0")]
|
||||
pub struct ValuesMut<'a, K: 'a, V: 'a> {
|
||||
inner: IterMut<'a, K, V>,
|
||||
@ -413,6 +418,7 @@ impl<K, V: fmt::Debug> fmt::Debug for ValuesMut<'_, K, V> {
|
||||
/// See its documentation for more.
|
||||
///
|
||||
/// [`into_keys`]: BTreeMap::into_keys
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
|
||||
pub struct IntoKeys<K, V> {
|
||||
inner: IntoIter<K, V>,
|
||||
@ -431,6 +437,7 @@ impl<K: fmt::Debug, V> fmt::Debug for IntoKeys<K, V> {
|
||||
/// See its documentation for more.
|
||||
///
|
||||
/// [`into_values`]: BTreeMap::into_values
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
|
||||
pub struct IntoValues<K, V> {
|
||||
inner: IntoIter<K, V>,
|
||||
@ -449,6 +456,7 @@ impl<K, V: fmt::Debug> fmt::Debug for IntoValues<K, V> {
|
||||
/// documentation for more.
|
||||
///
|
||||
/// [`range`]: BTreeMap::range
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "btree_range", since = "1.17.0")]
|
||||
pub struct Range<'a, K: 'a, V: 'a> {
|
||||
inner: LeafRange<marker::Immut<'a>, K, V>,
|
||||
@ -467,6 +475,7 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for Range<'_, K, V> {
|
||||
/// documentation for more.
|
||||
///
|
||||
/// [`range_mut`]: BTreeMap::range_mut
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "btree_range", since = "1.17.0")]
|
||||
pub struct RangeMut<'a, K: 'a, V: 'a> {
|
||||
inner: LeafRange<marker::ValMut<'a>, K, V>,
|
||||
@ -1265,7 +1274,6 @@ impl<K, V> BTreeMap<K, V> {
|
||||
/// assert_eq!(keys, [1, 2]);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
|
||||
pub fn into_keys(self) -> IntoKeys<K, V> {
|
||||
IntoKeys { inner: self.into_iter() }
|
||||
@ -1288,7 +1296,6 @@ impl<K, V> BTreeMap<K, V> {
|
||||
/// assert_eq!(values, ["hello", "goodbye"]);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
|
||||
pub fn into_values(self) -> IntoValues<K, V> {
|
||||
IntoValues { inner: self.into_iter() }
|
||||
|
@ -347,6 +347,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
|
||||
/// map.entry("poneyland").or_insert(12);
|
||||
/// assert_eq!(map.entry("poneyland").key(), &"poneyland");
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "map_entry_keys", since = "1.10.0")]
|
||||
pub fn key(&self) -> &K {
|
||||
self.handle.reborrow().into_kv().0
|
||||
@ -391,6 +392,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
|
||||
/// assert_eq!(o.get(), &12);
|
||||
/// }
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn get(&self) -> &V {
|
||||
self.handle.reborrow().into_kv().1
|
||||
|
@ -744,35 +744,35 @@ fn test_range_equal_empty_cases() {
|
||||
#[should_panic]
|
||||
fn test_range_equal_excluded() {
|
||||
let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect();
|
||||
map.range((Excluded(2), Excluded(2)));
|
||||
let _ = map.range((Excluded(2), Excluded(2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_range_backwards_1() {
|
||||
let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect();
|
||||
map.range((Included(3), Included(2)));
|
||||
let _ = map.range((Included(3), Included(2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_range_backwards_2() {
|
||||
let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect();
|
||||
map.range((Included(3), Excluded(2)));
|
||||
let _ = map.range((Included(3), Excluded(2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_range_backwards_3() {
|
||||
let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect();
|
||||
map.range((Excluded(3), Included(2)));
|
||||
let _ = map.range((Excluded(3), Included(2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_range_backwards_4() {
|
||||
let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect();
|
||||
map.range((Excluded(3), Excluded(2)));
|
||||
let _ = map.range((Excluded(3), Excluded(2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -783,7 +783,7 @@ fn test_range_finding_ill_order_in_map() {
|
||||
// we cause a different panic than `test_range_backwards_1` does.
|
||||
// A more refined `should_panic` would be welcome.
|
||||
if Cyclic3::C < Cyclic3::A {
|
||||
map.range(Cyclic3::C..=Cyclic3::A);
|
||||
let _ = map.range(Cyclic3::C..=Cyclic3::A);
|
||||
}
|
||||
}
|
||||
|
||||
@ -824,7 +824,7 @@ fn test_range_finding_ill_order_in_range_ord() {
|
||||
}
|
||||
|
||||
let map = (0..12).map(|i| (CompositeKey(i, EvilTwin(i)), ())).collect::<BTreeMap<_, _>>();
|
||||
map.range(EvilTwin(5)..=EvilTwin(7));
|
||||
let _ = map.range(EvilTwin(5)..=EvilTwin(7));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1239,32 +1239,32 @@ fn test_borrow() {
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn get<T: Ord>(v: &BTreeMap<Box<T>, ()>, t: &T) {
|
||||
v.get(t);
|
||||
let _ = v.get(t);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn get_mut<T: Ord>(v: &mut BTreeMap<Box<T>, ()>, t: &T) {
|
||||
v.get_mut(t);
|
||||
let _ = v.get_mut(t);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn get_key_value<T: Ord>(v: &BTreeMap<Box<T>, ()>, t: &T) {
|
||||
v.get_key_value(t);
|
||||
let _ = v.get_key_value(t);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn contains_key<T: Ord>(v: &BTreeMap<Box<T>, ()>, t: &T) {
|
||||
v.contains_key(t);
|
||||
let _ = v.contains_key(t);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn range<T: Ord>(v: &BTreeMap<Box<T>, ()>, t: T) {
|
||||
v.range(t..);
|
||||
let _ = v.range(t..);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn range_mut<T: Ord>(v: &mut BTreeMap<Box<T>, ()>, t: T) {
|
||||
v.range_mut(t..);
|
||||
let _ = v.range_mut(t..);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
@ -92,6 +92,7 @@ impl<T: Clone> Clone for BTreeSet<T> {
|
||||
/// See its documentation for more.
|
||||
///
|
||||
/// [`iter`]: BTreeSet::iter
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Iter<'a, T: 'a> {
|
||||
iter: Keys<'a, T, ()>,
|
||||
@ -123,6 +124,7 @@ pub struct IntoIter<T> {
|
||||
/// See its documentation for more.
|
||||
///
|
||||
/// [`range`]: BTreeSet::range
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[derive(Debug)]
|
||||
#[stable(feature = "btree_range", since = "1.17.0")]
|
||||
pub struct Range<'a, T: 'a> {
|
||||
@ -668,6 +670,7 @@ impl<T> BTreeSet<T> {
|
||||
/// set.insert(2);
|
||||
/// assert_eq!(set.first(), Some(&1));
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[unstable(feature = "map_first_last", issue = "62924")]
|
||||
pub fn first(&self) -> Option<&T>
|
||||
where
|
||||
@ -694,6 +697,7 @@ impl<T> BTreeSet<T> {
|
||||
/// set.insert(2);
|
||||
/// assert_eq!(set.last(), Some(&2));
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[unstable(feature = "map_first_last", issue = "62924")]
|
||||
pub fn last(&self) -> Option<&T>
|
||||
where
|
||||
|
@ -613,8 +613,8 @@ fn test_ord_absence() {
|
||||
set.is_empty();
|
||||
set.len();
|
||||
set.clear();
|
||||
set.iter();
|
||||
set.into_iter();
|
||||
let _ = set.iter();
|
||||
let _ = set.into_iter();
|
||||
}
|
||||
|
||||
fn set_debug<K: Debug>(set: BTreeSet<K>) {
|
||||
|
@ -64,6 +64,7 @@ struct Node<T> {
|
||||
///
|
||||
/// This `struct` is created by [`LinkedList::iter()`]. See its
|
||||
/// documentation for more.
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Iter<'a, T: 'a> {
|
||||
head: Option<NonNull<Node<T>>>,
|
||||
@ -99,6 +100,7 @@ impl<T> Clone for Iter<'_, T> {
|
||||
///
|
||||
/// This `struct` is created by [`LinkedList::iter_mut()`]. See its
|
||||
/// documentation for more.
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct IterMut<'a, T: 'a> {
|
||||
head: Option<NonNull<Node<T>>>,
|
||||
@ -529,6 +531,7 @@ impl<T> LinkedList<T> {
|
||||
///
|
||||
/// The cursor is pointing to the "ghost" non-element if the list is empty.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn cursor_front(&self) -> Cursor<'_, T> {
|
||||
Cursor { index: 0, current: self.head, list: self }
|
||||
@ -538,6 +541,7 @@ impl<T> LinkedList<T> {
|
||||
///
|
||||
/// The cursor is pointing to the "ghost" non-element if the list is empty.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn cursor_front_mut(&mut self) -> CursorMut<'_, T> {
|
||||
CursorMut { index: 0, current: self.head, list: self }
|
||||
@ -547,6 +551,7 @@ impl<T> LinkedList<T> {
|
||||
///
|
||||
/// The cursor is pointing to the "ghost" non-element if the list is empty.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn cursor_back(&self) -> Cursor<'_, T> {
|
||||
Cursor { index: self.len.checked_sub(1).unwrap_or(0), current: self.tail, list: self }
|
||||
@ -556,6 +561,7 @@ impl<T> LinkedList<T> {
|
||||
///
|
||||
/// The cursor is pointing to the "ghost" non-element if the list is empty.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn cursor_back_mut(&mut self) -> CursorMut<'_, T> {
|
||||
CursorMut { index: self.len.checked_sub(1).unwrap_or(0), current: self.tail, list: self }
|
||||
@ -678,6 +684,7 @@ impl<T> LinkedList<T> {
|
||||
/// assert_eq!(dl.front(), Some(&1));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn front(&self) -> Option<&T> {
|
||||
unsafe { self.head.as_ref().map(|node| &node.as_ref().element) }
|
||||
@ -706,6 +713,7 @@ impl<T> LinkedList<T> {
|
||||
/// assert_eq!(dl.front(), Some(&5));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn front_mut(&mut self) -> Option<&mut T> {
|
||||
unsafe { self.head.as_mut().map(|node| &mut node.as_mut().element) }
|
||||
@ -728,6 +736,7 @@ impl<T> LinkedList<T> {
|
||||
/// assert_eq!(dl.back(), Some(&1));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn back(&self) -> Option<&T> {
|
||||
unsafe { self.tail.as_ref().map(|node| &node.as_ref().element) }
|
||||
@ -1178,6 +1187,7 @@ impl<'a, T> Cursor<'a, T> {
|
||||
///
|
||||
/// This returns `None` if the cursor is currently pointing to the
|
||||
/// "ghost" non-element.
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn index(&self) -> Option<usize> {
|
||||
let _ = self.current?;
|
||||
@ -1232,6 +1242,7 @@ impl<'a, T> Cursor<'a, T> {
|
||||
///
|
||||
/// This returns `None` if the cursor is currently pointing to the
|
||||
/// "ghost" non-element.
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn current(&self) -> Option<&'a T> {
|
||||
unsafe { self.current.map(|current| &(*current.as_ptr()).element) }
|
||||
@ -1242,6 +1253,7 @@ impl<'a, T> Cursor<'a, T> {
|
||||
/// If the cursor is pointing to the "ghost" non-element then this returns
|
||||
/// the first element of the `LinkedList`. If it is pointing to the last
|
||||
/// element of the `LinkedList` then this returns `None`.
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn peek_next(&self) -> Option<&'a T> {
|
||||
unsafe {
|
||||
@ -1258,6 +1270,7 @@ impl<'a, T> Cursor<'a, T> {
|
||||
/// If the cursor is pointing to the "ghost" non-element then this returns
|
||||
/// the last element of the `LinkedList`. If it is pointing to the first
|
||||
/// element of the `LinkedList` then this returns `None`.
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn peek_prev(&self) -> Option<&'a T> {
|
||||
unsafe {
|
||||
@ -1271,6 +1284,7 @@ impl<'a, T> Cursor<'a, T> {
|
||||
|
||||
/// Provides a reference to the front element of the cursor's parent list,
|
||||
/// or None if the list is empty.
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn front(&self) -> Option<&'a T> {
|
||||
self.list.front()
|
||||
@ -1278,6 +1292,7 @@ impl<'a, T> Cursor<'a, T> {
|
||||
|
||||
/// Provides a reference to the back element of the cursor's parent list,
|
||||
/// or None if the list is empty.
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn back(&self) -> Option<&'a T> {
|
||||
self.list.back()
|
||||
@ -1289,6 +1304,7 @@ impl<'a, T> CursorMut<'a, T> {
|
||||
///
|
||||
/// This returns `None` if the cursor is currently pointing to the
|
||||
/// "ghost" non-element.
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn index(&self) -> Option<usize> {
|
||||
let _ = self.current?;
|
||||
@ -1343,6 +1359,7 @@ impl<'a, T> CursorMut<'a, T> {
|
||||
///
|
||||
/// This returns `None` if the cursor is currently pointing to the
|
||||
/// "ghost" non-element.
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn current(&mut self) -> Option<&mut T> {
|
||||
unsafe { self.current.map(|current| &mut (*current.as_ptr()).element) }
|
||||
@ -1631,6 +1648,7 @@ impl<'a, T> CursorMut<'a, T> {
|
||||
|
||||
/// Provides a reference to the front element of the cursor's parent list,
|
||||
/// or None if the list is empty.
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn front(&self) -> Option<&T> {
|
||||
self.list.front()
|
||||
@ -1638,6 +1656,7 @@ impl<'a, T> CursorMut<'a, T> {
|
||||
|
||||
/// Provides a mutable reference to the front element of the cursor's
|
||||
/// parent list, or None if the list is empty.
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn front_mut(&mut self) -> Option<&mut T> {
|
||||
self.list.front_mut()
|
||||
@ -1645,6 +1664,7 @@ impl<'a, T> CursorMut<'a, T> {
|
||||
|
||||
/// Provides a reference to the back element of the cursor's parent list,
|
||||
/// or None if the list is empty.
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn back(&self) -> Option<&T> {
|
||||
self.list.back()
|
||||
@ -1671,6 +1691,7 @@ impl<'a, T> CursorMut<'a, T> {
|
||||
/// assert_eq!(contents.next(), Some(0));
|
||||
/// assert_eq!(contents.next(), None);
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn back_mut(&mut self) -> Option<&mut T> {
|
||||
self.list.back_mut()
|
||||
|
@ -65,6 +65,7 @@ pub struct TryReserveError {
|
||||
impl TryReserveError {
|
||||
/// Details about the allocation that caused the error
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(
|
||||
feature = "try_reserve_kind",
|
||||
reason = "Uncertain how much info should be exposed",
|
||||
|
@ -572,6 +572,7 @@ use crate::string;
|
||||
/// [`format_args!`]: core::format_args
|
||||
/// [`format!`]: crate::format
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn format(args: Arguments<'_>) -> string::String {
|
||||
let capacity = args.estimated_capacity();
|
||||
|
@ -2246,6 +2246,7 @@ impl<T: ?Sized> Weak<T> {
|
||||
/// Gets the number of strong (`Rc`) pointers pointing to this allocation.
|
||||
///
|
||||
/// If `self` was created using [`Weak::new`], this will return 0.
|
||||
#[must_use]
|
||||
#[stable(feature = "weak_counts", since = "1.41.0")]
|
||||
pub fn strong_count(&self) -> usize {
|
||||
if let Some(inner) = self.inner() { inner.strong() } else { 0 }
|
||||
@ -2254,6 +2255,7 @@ impl<T: ?Sized> Weak<T> {
|
||||
/// Gets the number of `Weak` pointers pointing to this allocation.
|
||||
///
|
||||
/// If no strong pointers remain, this will return zero.
|
||||
#[must_use]
|
||||
#[stable(feature = "weak_counts", since = "1.41.0")]
|
||||
pub fn weak_count(&self) -> usize {
|
||||
self.inner()
|
||||
@ -2324,6 +2326,7 @@ impl<T: ?Sized> Weak<T> {
|
||||
/// assert!(!first.ptr_eq(&third));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "weak_ptr_eq", since = "1.39.0")]
|
||||
pub fn ptr_eq(&self, other: &Self) -> bool {
|
||||
self.ptr.as_ptr() == other.ptr.as_ptr()
|
||||
|
@ -243,6 +243,7 @@ impl str {
|
||||
/// assert_eq!(*boxed_bytes, *s.as_bytes());
|
||||
/// ```
|
||||
#[stable(feature = "str_box_extras", since = "1.20.0")]
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[inline]
|
||||
pub fn into_boxed_bytes(self: Box<str>) -> Box<[u8]> {
|
||||
self.into()
|
||||
@ -484,6 +485,7 @@ impl str {
|
||||
/// assert_eq!(boxed_str.into_string(), string);
|
||||
/// ```
|
||||
#[stable(feature = "box_str", since = "1.4.0")]
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[inline]
|
||||
pub fn into_string(self: Box<str>) -> String {
|
||||
let slice = Box::<[u8]>::from(self);
|
||||
@ -508,9 +510,10 @@ impl str {
|
||||
///
|
||||
/// ```should_panic
|
||||
/// // this will panic at runtime
|
||||
/// "0123456789abcdef".repeat(usize::MAX);
|
||||
/// let huge = "0123456789abcdef".repeat(usize::MAX);
|
||||
/// ```
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[must_use]
|
||||
#[stable(feature = "repeat_str", since = "1.16.0")]
|
||||
pub fn repeat(&self, n: usize) -> String {
|
||||
unsafe { String::from_utf8_unchecked(self.as_bytes().repeat(n)) }
|
||||
|
@ -898,6 +898,7 @@ impl String {
|
||||
/// assert!(s.capacity() >= 10);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn capacity(&self) -> usize {
|
||||
self.vec.capacity()
|
||||
@ -1822,6 +1823,7 @@ impl FromUtf8Error {
|
||||
/// // the first byte is invalid here
|
||||
/// assert_eq!(1, error.valid_up_to());
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn utf8_error(&self) -> Utf8Error {
|
||||
self.error
|
||||
|
@ -953,6 +953,7 @@ impl<T: ?Sized> Arc<T> {
|
||||
/// assert_eq!(1, Arc::weak_count(&five));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "arc_counts", since = "1.15.0")]
|
||||
pub fn weak_count(this: &Self) -> usize {
|
||||
let cnt = this.inner().weak.load(SeqCst);
|
||||
@ -982,6 +983,7 @@ impl<T: ?Sized> Arc<T> {
|
||||
/// assert_eq!(2, Arc::strong_count(&five));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "arc_counts", since = "1.15.0")]
|
||||
pub fn strong_count(this: &Self) -> usize {
|
||||
this.inner().strong.load(SeqCst)
|
||||
@ -1079,8 +1081,6 @@ impl<T: ?Sized> Arc<T> {
|
||||
drop(Weak { ptr: self.ptr });
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[stable(feature = "ptr_eq", since = "1.17.0")]
|
||||
/// Returns `true` if the two `Arc`s point to the same allocation
|
||||
/// (in a vein similar to [`ptr::eq`]).
|
||||
///
|
||||
@ -1098,6 +1098,9 @@ impl<T: ?Sized> Arc<T> {
|
||||
/// ```
|
||||
///
|
||||
/// [`ptr::eq`]: core::ptr::eq "ptr::eq"
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "ptr_eq", since = "1.17.0")]
|
||||
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
|
||||
this.ptr.as_ptr() == other.ptr.as_ptr()
|
||||
}
|
||||
@ -1904,6 +1907,7 @@ impl<T: ?Sized> Weak<T> {
|
||||
/// Gets the number of strong (`Arc`) pointers pointing to this allocation.
|
||||
///
|
||||
/// If `self` was created using [`Weak::new`], this will return 0.
|
||||
#[must_use]
|
||||
#[stable(feature = "weak_counts", since = "1.41.0")]
|
||||
pub fn strong_count(&self) -> usize {
|
||||
if let Some(inner) = self.inner() { inner.strong.load(SeqCst) } else { 0 }
|
||||
@ -1920,6 +1924,7 @@ impl<T: ?Sized> Weak<T> {
|
||||
/// Due to implementation details, the returned value can be off by 1 in
|
||||
/// either direction when other threads are manipulating any `Arc`s or
|
||||
/// `Weak`s pointing to the same allocation.
|
||||
#[must_use]
|
||||
#[stable(feature = "weak_counts", since = "1.41.0")]
|
||||
pub fn weak_count(&self) -> usize {
|
||||
self.inner()
|
||||
@ -1999,6 +2004,7 @@ impl<T: ?Sized> Weak<T> {
|
||||
///
|
||||
/// [`ptr::eq`]: core::ptr::eq "ptr::eq"
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "weak_ptr_eq", since = "1.39.0")]
|
||||
pub fn ptr_eq(&self, other: &Self) -> bool {
|
||||
self.ptr.as_ptr() == other.ptr.as_ptr()
|
||||
|
@ -60,6 +60,7 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> {
|
||||
|
||||
/// Returns a reference to the underlying allocator.
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn allocator(&self) -> &A {
|
||||
unsafe { self.vec.as_ref().allocator() }
|
||||
|
Loading…
x
Reference in New Issue
Block a user