Skip to content

Commit a827700

Browse files
authored
Rollup merge of rust-lang#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! } ```
2 parents dd7fda5 + ac3c480 commit a827700

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

library/alloc/src/collections/vec_deque/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,8 +1486,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
14861486
///
14871487
/// # Panics
14881488
///
1489-
/// Panics if the starting point is greater than the end point or if
1490-
/// the end point is greater than the length of the deque.
1489+
/// Panics if the range has `start_bound > end_bound`, or, if the range is
1490+
/// bounded on either end and past the length of the deque.
14911491
///
14921492
/// # Examples
14931493
///
@@ -1522,8 +1522,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
15221522
///
15231523
/// # Panics
15241524
///
1525-
/// Panics if the starting point is greater than the end point or if
1526-
/// the end point is greater than the length of the deque.
1525+
/// Panics if the range has `start_bound > end_bound`, or, if the range is
1526+
/// bounded on either end and past the length of the deque.
15271527
///
15281528
/// # Examples
15291529
///
@@ -1568,8 +1568,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
15681568
///
15691569
/// # Panics
15701570
///
1571-
/// Panics if the starting point is greater than the end point or if
1572-
/// the end point is greater than the length of the deque.
1571+
/// Panics if the range has `start_bound > end_bound`, or, if the range is
1572+
/// bounded on either end and past the length of the deque.
15731573
///
15741574
/// # Leaking
15751575
///

library/alloc/src/string.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,8 +1117,8 @@ impl String {
11171117
///
11181118
/// # Panics
11191119
///
1120-
/// Panics if the starting point or end point do not lie on a [`char`]
1121-
/// boundary, or if they're out of bounds.
1120+
/// Panics if the range has `start_bound > end_bound`, or, if the range is
1121+
/// bounded on either end and does not lie on a [`char`] boundary.
11221122
///
11231123
/// # Examples
11241124
///
@@ -1939,8 +1939,8 @@ impl String {
19391939
///
19401940
/// # Panics
19411941
///
1942-
/// Panics if the starting point or end point do not lie on a [`char`]
1943-
/// boundary, or if they're out of bounds.
1942+
/// Panics if the range has `start_bound > end_bound`, or, if the range is
1943+
/// bounded on either end and does not lie on a [`char`] boundary.
19441944
///
19451945
/// # Leaking
19461946
///
@@ -2050,8 +2050,8 @@ impl String {
20502050
///
20512051
/// # Panics
20522052
///
2053-
/// Panics if the starting point or end point do not lie on a [`char`]
2054-
/// boundary, or if they're out of bounds.
2053+
/// Panics if the range has `start_bound > end_bound`, or, if the range is
2054+
/// bounded on either end and does not lie on a [`char`] boundary.
20552055
///
20562056
/// # Examples
20572057
///

library/alloc/src/vec/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,8 +2796,8 @@ impl<T, A: Allocator> Vec<T, A> {
27962796
///
27972797
/// # Panics
27982798
///
2799-
/// Panics if the starting point is greater than the end point or if
2800-
/// the end point is greater than the length of the vector.
2799+
/// Panics if the range has `start_bound > end_bound`, or, if the range is
2800+
/// bounded on either end and past the length of the vector.
28012801
///
28022802
/// # Leaking
28032803
///
@@ -3860,8 +3860,8 @@ impl<T, A: Allocator> Vec<T, A> {
38603860
///
38613861
/// # Panics
38623862
///
3863-
/// Panics if the starting point is greater than the end point or if
3864-
/// the end point is greater than the length of the vector.
3863+
/// Panics if the range has `start_bound > end_bound`, or, if the range is
3864+
/// bounded on either end and past the length of the vector.
38653865
///
38663866
/// # Examples
38673867
///

0 commit comments

Comments
 (0)