Rollup merge of #140983 - tkr-sh:master, r=ibraheemdev
Improve doc of some methods that take ranges Some methods that were taking some range in parameter were a bit inconsistent / unclear in the panic documentation. Here is the recap: - Replaced "start/end point" by "start/end bound" to be coherent with [`RangeBounds`](https://doc.rust-lang.org/stable/std/ops/trait.RangeBounds.html) naming (it's also easier to understand I think) - Previously, it was written "_[...] or if the end point is greater than the length of [...]_", but this is not entirely true! Actually, you can have a start bound that is greater than the length, with an end bound that is unbounded and it will also panic. Therefore I think that "_[...] one of the range bound is bounded and greater than the length of [...]_" is better! - `String` methods weren't mentionning that the method panics if `start_bound > end_bound` but it actually does! It uses `slice::range` which panics when `start > end`. (https://doc.rust-lang.org/stable/src/alloc/string.rs.html#1932-1934, https://doc.rust-lang.org/stable/src/core/slice/index.rs.html#835-837). You can also test it with: ```rs struct MyRange; impl std::ops::RangeBounds<usize> for MyRange { fn start_bound(&self) -> std::ops::Bound<&usize> { std::ops::Bound::Included(&3usize) } fn end_bound(&self) -> std::ops::Bound<&usize> { std::ops::Bound::Included(&1usize) } } fn main() { let mut s = String::from("I love Rust!"); s.drain(MyRange); // panics! } ```
This commit is contained in:
commit
d2533189de
3 changed files with 16 additions and 16 deletions
|
|
@ -1486,8 +1486,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
|
|||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the starting point is greater than the end point or if
|
||||
/// the end point is greater than the length of the deque.
|
||||
/// Panics if the range has `start_bound > end_bound`, or, if the range is
|
||||
/// bounded on either end and past the length of the deque.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
|
@ -1522,8 +1522,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
|
|||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the starting point is greater than the end point or if
|
||||
/// the end point is greater than the length of the deque.
|
||||
/// Panics if the range has `start_bound > end_bound`, or, if the range is
|
||||
/// bounded on either end and past the length of the deque.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
|
@ -1568,8 +1568,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
|
|||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the starting point is greater than the end point or if
|
||||
/// the end point is greater than the length of the deque.
|
||||
/// Panics if the range has `start_bound > end_bound`, or, if the range is
|
||||
/// bounded on either end and past the length of the deque.
|
||||
///
|
||||
/// # Leaking
|
||||
///
|
||||
|
|
|
|||
|
|
@ -1117,8 +1117,8 @@ impl String {
|
|||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the starting point or end point do not lie on a [`char`]
|
||||
/// boundary, or if they're out of bounds.
|
||||
/// Panics if the range has `start_bound > end_bound`, or, if the range is
|
||||
/// bounded on either end and does not lie on a [`char`] boundary.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
|
@ -1939,8 +1939,8 @@ impl String {
|
|||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the starting point or end point do not lie on a [`char`]
|
||||
/// boundary, or if they're out of bounds.
|
||||
/// Panics if the range has `start_bound > end_bound`, or, if the range is
|
||||
/// bounded on either end and does not lie on a [`char`] boundary.
|
||||
///
|
||||
/// # Leaking
|
||||
///
|
||||
|
|
@ -2050,8 +2050,8 @@ impl String {
|
|||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the starting point or end point do not lie on a [`char`]
|
||||
/// boundary, or if they're out of bounds.
|
||||
/// Panics if the range has `start_bound > end_bound`, or, if the range is
|
||||
/// bounded on either end and does not lie on a [`char`] boundary.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
|
|
|||
|
|
@ -2796,8 +2796,8 @@ impl<T, A: Allocator> Vec<T, A> {
|
|||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the starting point is greater than the end point or if
|
||||
/// the end point is greater than the length of the vector.
|
||||
/// Panics if the range has `start_bound > end_bound`, or, if the range is
|
||||
/// bounded on either end and past the length of the vector.
|
||||
///
|
||||
/// # Leaking
|
||||
///
|
||||
|
|
@ -3860,8 +3860,8 @@ impl<T, A: Allocator> Vec<T, A> {
|
|||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the starting point is greater than the end point or if
|
||||
/// the end point is greater than the length of the vector.
|
||||
/// Panics if the range has `start_bound > end_bound`, or, if the range is
|
||||
/// bounded on either end and past the length of the vector.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue