Skip to content

Commit

Permalink
Rollup merge of rust-lang#69385 - ridiculousfish:relax_get_unchecked,…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
Dylan-DPC committed Feb 24, 2020
2 parents a4ba75b + 9e41c4b commit 5f16272
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/libcore/str/mod.rs
Expand Up @@ -2486,7 +2486,7 @@ impl str {
/// Callers of this function are responsible that these preconditions are
/// satisfied:
///
/// * The starting index must come before the ending index;
/// * The starting index must not exceed the ending index;
/// * Indexes must be within bounds of the original slice;
/// * Indexes must lie on UTF-8 sequence boundaries.
///
Expand Down Expand Up @@ -2518,7 +2518,7 @@ impl str {
/// Callers of this function are responsible that these preconditions are
/// satisfied:
///
/// * The starting index must come before the ending index;
/// * The starting index must not exceed the ending index;
/// * Indexes must be within bounds of the original slice;
/// * Indexes must lie on UTF-8 sequence boundaries.
///
Expand Down Expand Up @@ -2563,7 +2563,7 @@ impl str {
/// Callers of this function are responsible that three preconditions are
/// satisfied:
///
/// * `begin` must come before `end`.
/// * `begin` must not exceed `end`.
/// * `begin` and `end` must be byte positions within the string slice.
/// * `begin` and `end` must lie on UTF-8 sequence boundaries.
///
Expand Down Expand Up @@ -2612,7 +2612,7 @@ impl str {
/// Callers of this function are responsible that three preconditions are
/// satisfied:
///
/// * `begin` must come before `end`.
/// * `begin` must not exceed `end`.
/// * `begin` and `end` must be byte positions within the string slice.
/// * `begin` and `end` must lie on UTF-8 sequence boundaries.
#[stable(feature = "str_slice_mut", since = "1.5.0")]
Expand Down

0 comments on commit 5f16272

Please sign in to comment.