Skip to content

Commit 4aeeb81

Browse files
authored
Rollup merge of #70588 - Coder-256:str-split-at-docs, r=Dylan-DPC
Fix incorrect documentation for `str::{split_at, split_at_mut}` The documentation for each method currently states: > Panics if `mid` is not on a UTF-8 code point boundary, or if it is beyond the last code point of the string slice. However, this is not consistent with the real behavior, or that of the corresponding methods for `[T]` slices. A comment inside each of the `str` methods states: > is_char_boundary checks that the index is in [0, .len()] That is what I would expect the behavior to be, and in fact this seems to be the real behavior. For example ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=8e03dcc209d4dd176df2297523f9fee1)): ```rust fn main() { // Prints ("abc", "") and doesn't panic println!("{:?}", "abc".split_at(3)); } ``` In this case, I would interpret "the last code point of the string slice" to mean the byte at index 2 in UTF-8. However, it is possible to pass an index of 3, which is definitely "beyond the last code point of the string slice". I think that this is much clearer, but feel free to bikeshed.
2 parents c55f500 + fcab1f9 commit 4aeeb81

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/libcore/str/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2642,7 +2642,7 @@ impl str {
26422642
/// # Panics
26432643
///
26442644
/// Panics if `mid` is not on a UTF-8 code point boundary, or if it is
2645-
/// beyond the last code point of the string slice.
2645+
/// past the end of the last code point of the string slice.
26462646
///
26472647
/// # Examples
26482648
///
@@ -2683,7 +2683,7 @@ impl str {
26832683
/// # Panics
26842684
///
26852685
/// Panics if `mid` is not on a UTF-8 code point boundary, or if it is
2686-
/// beyond the last code point of the string slice.
2686+
/// past the end of the last code point of the string slice.
26872687
///
26882688
/// # Examples
26892689
///

0 commit comments

Comments
 (0)