@@ -3797,7 +3797,7 @@ impl str {
3797
3797
/// the prefix is removed. Unlike `trim_start_matches`, this method removes the prefix exactly
3798
3798
/// once.
3799
3799
///
3800
- /// If the string does not start with `prefix`, it is removed .
3800
+ /// If the string does not start with `prefix`, `None` is returned .
3801
3801
///
3802
3802
/// # Examples
3803
3803
///
@@ -3814,8 +3814,9 @@ impl str {
3814
3814
pub fn strip_prefix < ' a , P : Pattern < ' a > > ( & ' a self , prefix : P ) -> Option < & ' a str > {
3815
3815
let mut matcher = prefix. into_searcher ( self ) ;
3816
3816
if let SearchStep :: Match ( start, len) = matcher. next ( ) {
3817
- debug_assert_eq ! ( start, 0 ) ;
3817
+ debug_assert_eq ! ( start, 0 , "The first search step from Searcher must start from the front" ) ;
3818
3818
unsafe {
3819
+ // Searcher is known to return valid indices.
3819
3820
Some ( self . get_unchecked ( len..) )
3820
3821
}
3821
3822
} else {
@@ -3825,11 +3826,11 @@ impl str {
3825
3826
3826
3827
/// Returns a string slice with the suffix removed.
3827
3828
///
3828
- /// If the string starts with the pattern `suffix`, `Some` is returned with the substring where
3829
+ /// If the string ends with the pattern `suffix`, `Some` is returned with the substring where
3829
3830
/// the suffix is removed. Unlike `trim_end_matches`, this method removes the suffix exactly
3830
3831
/// once.
3831
3832
///
3832
- /// If the string does not start with `suffix`, it is removed .
3833
+ /// If the string does not end with `suffix`, `None` is returned .
3833
3834
///
3834
3835
/// # Examples
3835
3836
///
@@ -3849,8 +3850,9 @@ impl str {
3849
3850
{
3850
3851
let mut matcher = suffix. into_searcher ( self ) ;
3851
3852
if let SearchStep :: Match ( start, end) = matcher. next_back ( ) {
3852
- debug_assert_eq ! ( end, self . len( ) ) ;
3853
+ debug_assert_eq ! ( end, self . len( ) , "The first search step from ReverseSearcher must include the last character" ) ;
3853
3854
unsafe {
3855
+ // Searcher is known to return valid indices.
3854
3856
Some ( self . get_unchecked ( ..start) )
3855
3857
}
3856
3858
} else {
0 commit comments