Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/alloc/src/collections/binary_heap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ impl<T, A: Allocator> BinaryHeap<T, A> {
///
/// Ok(heap.pop())
/// }
/// # find_max_slow(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?");
/// # find_max_slow(&[1, 2, 3]).expect("reserving capacity for 12 bytes should never fail");
/// ```
#[stable(feature = "try_reserve_2", since = "1.63.0")]
pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> {
Expand Down Expand Up @@ -1294,7 +1294,7 @@ impl<T, A: Allocator> BinaryHeap<T, A> {
///
/// Ok(heap.pop())
/// }
/// # find_max_slow(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?");
/// # find_max_slow(&[1, 2, 3]).expect("reserving capacity for 12 bytes should never fail");
/// ```
#[stable(feature = "try_reserve_2", since = "1.63.0")]
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
Expand Down
12 changes: 6 additions & 6 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "vecdeque_reserve")]
pub fn reserve(&mut self, additional: usize) {
let new_cap = self.len.checked_add(additional).expect("capacity overflow");
let new_cap = self.len.checked_add(additional).expect("length should not overflow usize");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one I don't think we should change. It's an overflow that can actually happen for some user-provided values of additional, so the message shouldn't claim that this will not overflow when it actually can overflow. Instead the message should be tailored to be usefulf for the caller.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should use let else for some of these with an explicit panic rather than expect, since I would rather not want expect to be used for "regular panic"s that just occur due to bad user input.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but that seems like a bigger change than fixing part of #159751

let old_cap = self.capacity();

if new_cap > old_cap {
Expand Down Expand Up @@ -1153,7 +1153,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
///
/// Ok(output)
/// }
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?");
/// # process_data(&[1, 2, 3]).expect("reserving capacity for 12 bytes should never fail");
/// ```
#[stable(feature = "try_reserve", since = "1.57.0")]
pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> {
Expand Down Expand Up @@ -1201,7 +1201,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
///
/// Ok(output)
/// }
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?");
/// # process_data(&[1, 2, 3]).expect("reserving capacity for 12 bytes should never fail");
/// ```
#[stable(feature = "try_reserve", since = "1.57.0")]
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
Expand Down Expand Up @@ -2732,7 +2732,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
#[stable(feature = "append", since = "1.4.0")]
pub fn append(&mut self, other: &mut Self) {
if T::IS_ZST {
self.len = self.len.checked_add(other.len).expect("capacity overflow");
self.len = self.len.checked_add(other.len).expect("length should not overflow usize");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same applies here.

other.len = 0;
other.head = WrappedIndex::zero();
return;
Expand Down Expand Up @@ -3871,15 +3871,15 @@ impl<T, A: Allocator> Index<usize> for VecDeque<T, A> {

#[inline]
fn index(&self, index: usize) -> &T {
self.get(index).expect("Out of bounds access")
self.get(index).expect("index should be within bounds")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T, A: Allocator> IndexMut<usize> for VecDeque<T, A> {
#[inline]
fn index_mut(&mut self, index: usize) -> &mut T {
self.get_mut(index).expect("Out of bounds access")
self.get_mut(index).expect("index should be within bounds")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

}
}

Expand Down
Loading