-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Update expect message using the recommended style in binary_heap module #159821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"); | ||
| let old_cap = self.capacity(); | ||
|
|
||
| if new_cap > old_cap { | ||
|
|
@@ -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> { | ||
|
|
@@ -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> { | ||
|
|
@@ -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"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same applies here. |
||
| other.len = 0; | ||
| other.head = WrappedIndex::zero(); | ||
| return; | ||
|
|
@@ -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") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here. |
||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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 wantexpectto be used for "regular panic"s that just occur due to bad user input.There was a problem hiding this comment.
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