@@ -215,6 +215,8 @@ where
215215 let end = hay. end_index ( ) ;
216216 start..end
217217 } ;
218+ // SAFETY: the start and end indices of `range` are returned from `trim_start` and `end_index`,
219+ // and both are valid indices.
218220 unsafe { haystack. slice_unchecked ( range) }
219221}
220222
@@ -232,6 +234,8 @@ where
232234 let end = needle. into_consumer ( ) . trim_end ( hay) ;
233235 start..end
234236 } ;
237+ // SAFETY: the start and end indices of `range` are returned from `start_index` and `trim_end`,
238+ // and both are valid indices.
235239 unsafe { haystack. slice_unchecked ( range) }
236240}
237241
@@ -248,10 +252,14 @@ where
248252 let range = {
249253 let hay = & * haystack;
250254 let end = checker. trim_end ( hay) ;
255+ // SAFETY: the start and end indices are returned from `start_index` and `trim_end`,
256+ // and both are valid indices.
251257 let hay = unsafe { Hay :: slice_unchecked ( hay, hay. start_index ( ) ..end) } ;
252258 let start = checker. trim_start ( hay) ;
253259 start..end
254260 } ;
261+ // SAFETY: the start and end indices of `range` are returned from `trim_start` and `trim_end`,
262+ // and both are valid indices.
255263 unsafe { haystack. slice_unchecked ( range) }
256264}
257265
@@ -279,6 +287,8 @@ where
279287 fn next_spanned ( & mut self ) -> Option < Span < H > > {
280288 let rest = self . rest . take ( ) ;
281289 let range = self . searcher . search ( rest. borrow ( ) ) ?;
290+ // SAFETY: the start and end indices of `range` are returned from `search`,
291+ // and both are valid indices.
282292 let [ _, middle, right] = unsafe { rest. split_around ( range) } ;
283293 self . rest = right;
284294 Some ( middle)
@@ -300,6 +310,8 @@ where
300310 fn next_back_spanned ( & mut self ) -> Option < Span < H > > {
301311 let rest = self . rest . take ( ) ;
302312 let range = self . searcher . rsearch ( rest. borrow ( ) ) ?;
313+ // SAFETY: the start and end indices of `range` are returned from `rsearch`,
314+ // and both are valid indices.
303315 let [ left, middle, _] = unsafe { rest. split_around ( range) } ;
304316 self . rest = left;
305317 Some ( middle)
@@ -608,6 +620,8 @@ where
608620 let mut rest = self . rest . take ( ) ;
609621 match self . searcher . search ( rest. borrow ( ) ) {
610622 Some ( subrange) => {
623+ // SAFETY: the start and end indices of `subrange` are returned from `search`,
624+ // and both are valid indices.
611625 let [ left, _, right] = unsafe { rest. split_around ( subrange) } ;
612626 self . rest = right;
613627 rest = left;
@@ -638,6 +652,8 @@ where
638652 let rest = self . rest . take ( ) ;
639653 let after = match self . searcher . rsearch ( rest. borrow ( ) ) {
640654 Some ( range) => {
655+ // SAFETY: the start and end indices of `subrange` are returned from `rsearch`,
656+ // and both are valid indices.
641657 let [ left, _, right] = unsafe { rest. split_around ( range) } ;
642658 self . rest = left;
643659 right
@@ -792,6 +808,8 @@ where
792808 }
793809 n => match self . searcher . search ( rest. borrow ( ) ) {
794810 Some ( range) => {
811+ // SAFETY: the start and end indices of `range` are returned from `search`,
812+ // and both are valid indices.
795813 let [ left, _, right] = unsafe { rest. split_around ( range) } ;
796814 self . n = n - 1 ;
797815 self . rest = right;
@@ -824,6 +842,8 @@ where
824842 }
825843 n => match self . searcher . rsearch ( rest. borrow ( ) ) {
826844 Some ( range) => {
845+ // SAFETY: the start and end indices of `range` are returned from `rsearch`,
846+ // and both are valid indices.
827847 let [ left, _, right] = unsafe { rest. split_around ( range) } ;
828848 self . n = n - 1 ;
829849 self . rest = left;
@@ -896,6 +916,8 @@ where
896916 let mut searcher = from. into_searcher ( ) ;
897917 let mut src = Span :: from ( src) ;
898918 while let Some ( range) = searcher. search ( src. borrow ( ) ) {
919+ // SAFETY: the start and end indices of `range` are returned from `search`,
920+ // and both are valid indices.
899921 let [ left, middle, right] = unsafe { src. split_around ( range) } ;
900922 writer ( Span :: into ( left) ) ;
901923 writer ( replacer ( Span :: into ( middle) ) ) ;
@@ -921,6 +943,8 @@ where
921943 }
922944 n -= 1 ;
923945 if let Some ( range) = searcher. search ( src. borrow ( ) ) {
946+ // SAFETY: the start and end indices of `range` are returned from `search`,
947+ // and both are valid indices.
924948 let [ left, middle, right] = unsafe { src. split_around ( range) } ;
925949 writer ( Span :: into ( left) ) ;
926950 writer ( replacer ( Span :: into ( middle) ) ) ;
0 commit comments