about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorStuart Cook <Zalathar@users.noreply.github.com>2025-09-21 14:42:32 +1000
committerGitHub <noreply@github.com>2025-09-21 14:42:32 +1000
commitd2533189ded231436f4db4975da476e7630eaed2 (patch)
tree2e42f5b0af0fcbe09d1b647a2699085a549b1305 /compiler
parentdd7fda570040e8a736f7d8bc28ddd1b444aabc82 (diff)
parentac3c480388d27ee9ebeb23d308bd37289d37bc41 (diff)
downloadrust-d2533189ded231436f4db4975da476e7630eaed2.tar.gz
rust-d2533189ded231436f4db4975da476e7630eaed2.zip
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!
}
```
Diffstat (limited to 'compiler')
0 files changed, 0 insertions, 0 deletions