Skip to content

Commit 5f16272

Browse files
authored
Rollup merge of #69385 - ridiculousfish:relax_get_unchecked, r=nagisa
Relax str::get_unchecked precondition to permit empty slicing Prior to this commit, `str` documented that `get_unchecked` had the precondition that "`begin` must come before `end`". This would appear to prohibit empty slices (i.e. begin == end). In practice, get_unchecked is called often with empty slices. Let's relax the precondition so as to allow them.
2 parents a4ba75b + 9e41c4b commit 5f16272

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/libcore/str/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2486,7 +2486,7 @@ impl str {
24862486
/// Callers of this function are responsible that these preconditions are
24872487
/// satisfied:
24882488
///
2489-
/// * The starting index must come before the ending index;
2489+
/// * The starting index must not exceed the ending index;
24902490
/// * Indexes must be within bounds of the original slice;
24912491
/// * Indexes must lie on UTF-8 sequence boundaries.
24922492
///
@@ -2518,7 +2518,7 @@ impl str {
25182518
/// Callers of this function are responsible that these preconditions are
25192519
/// satisfied:
25202520
///
2521-
/// * The starting index must come before the ending index;
2521+
/// * The starting index must not exceed the ending index;
25222522
/// * Indexes must be within bounds of the original slice;
25232523
/// * Indexes must lie on UTF-8 sequence boundaries.
25242524
///
@@ -2563,7 +2563,7 @@ impl str {
25632563
/// Callers of this function are responsible that three preconditions are
25642564
/// satisfied:
25652565
///
2566-
/// * `begin` must come before `end`.
2566+
/// * `begin` must not exceed `end`.
25672567
/// * `begin` and `end` must be byte positions within the string slice.
25682568
/// * `begin` and `end` must lie on UTF-8 sequence boundaries.
25692569
///
@@ -2612,7 +2612,7 @@ impl str {
26122612
/// Callers of this function are responsible that three preconditions are
26132613
/// satisfied:
26142614
///
2615-
/// * `begin` must come before `end`.
2615+
/// * `begin` must not exceed `end`.
26162616
/// * `begin` and `end` must be byte positions within the string slice.
26172617
/// * `begin` and `end` must lie on UTF-8 sequence boundaries.
26182618
#[stable(feature = "str_slice_mut", since = "1.5.0")]

0 commit comments

Comments
 (0)