diff options
| author | ltdk <usr@ltdk.xyz> | 2023-06-07 10:48:28 -0400 |
|---|---|---|
| committer | ltdk <usr@ltdk.xyz> | 2023-06-07 10:48:28 -0400 |
| commit | 43453a8ebf183912cff3448223e6202375560ffa (patch) | |
| tree | 3612146c8f2dfa779f2a7e9582f64b1b4341c47e | |
| parent | e94bda3bf13303671427363d1cd93ac5e089f090 (diff) | |
| download | rust-43453a8ebf183912cff3448223e6202375560ffa.tar.gz rust-43453a8ebf183912cff3448223e6202375560ffa.zip | |
Don't panic in ceil_char_boundary
| -rw-r--r-- | library/core/src/str/mod.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index ef05b25fdd0..99219914fd2 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -271,14 +271,13 @@ impl str { /// Finds the closest `x` not below `index` where `is_char_boundary(x)` is `true`. /// + /// If `x` is greater than the length of the string, this returns the length of the string. + /// /// This method is the natural complement to [`floor_char_boundary`]. See that method /// for more details. /// /// [`floor_char_boundary`]: str::floor_char_boundary /// - /// # Panics - /// - /// Panics if `index > self.len()`. /// /// # Examples /// @@ -296,7 +295,7 @@ impl str { #[inline] pub fn ceil_char_boundary(&self, index: usize) -> usize { if index > self.len() { - slice_error_fail(self, index, index) + self.len() } else { let upper_bound = Ord::min(index + 4, self.len()); self.as_bytes()[index..upper_bound] |
