@@ -215,6 +215,8 @@ where
215
215
let end = hay. end_index ( ) ;
216
216
start..end
217
217
} ;
218
+ // SAFETY: the start and end indices of `range` are returned from `trim_start` and `end_index`,
219
+ // and both are valid indices.
218
220
unsafe { haystack. slice_unchecked ( range) }
219
221
}
220
222
@@ -232,6 +234,8 @@ where
232
234
let end = needle. into_consumer ( ) . trim_end ( hay) ;
233
235
start..end
234
236
} ;
237
+ // SAFETY: the start and end indices of `range` are returned from `start_index` and `trim_end`,
238
+ // and both are valid indices.
235
239
unsafe { haystack. slice_unchecked ( range) }
236
240
}
237
241
@@ -248,10 +252,14 @@ where
248
252
let range = {
249
253
let hay = & * haystack;
250
254
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.
251
257
let hay = unsafe { Hay :: slice_unchecked ( hay, hay. start_index ( ) ..end) } ;
252
258
let start = checker. trim_start ( hay) ;
253
259
start..end
254
260
} ;
261
+ // SAFETY: the start and end indices of `range` are returned from `trim_start` and `trim_end`,
262
+ // and both are valid indices.
255
263
unsafe { haystack. slice_unchecked ( range) }
256
264
}
257
265
@@ -279,6 +287,8 @@ where
279
287
fn next_spanned ( & mut self ) -> Option < Span < H > > {
280
288
let rest = self . rest . take ( ) ;
281
289
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.
282
292
let [ _, middle, right] = unsafe { rest. split_around ( range) } ;
283
293
self . rest = right;
284
294
Some ( middle)
@@ -300,6 +310,8 @@ where
300
310
fn next_back_spanned ( & mut self ) -> Option < Span < H > > {
301
311
let rest = self . rest . take ( ) ;
302
312
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.
303
315
let [ left, middle, _] = unsafe { rest. split_around ( range) } ;
304
316
self . rest = left;
305
317
Some ( middle)
@@ -608,6 +620,8 @@ where
608
620
let mut rest = self . rest . take ( ) ;
609
621
match self . searcher . search ( rest. borrow ( ) ) {
610
622
Some ( subrange) => {
623
+ // SAFETY: the start and end indices of `subrange` are returned from `search`,
624
+ // and both are valid indices.
611
625
let [ left, _, right] = unsafe { rest. split_around ( subrange) } ;
612
626
self . rest = right;
613
627
rest = left;
@@ -638,6 +652,8 @@ where
638
652
let rest = self . rest . take ( ) ;
639
653
let after = match self . searcher . rsearch ( rest. borrow ( ) ) {
640
654
Some ( range) => {
655
+ // SAFETY: the start and end indices of `subrange` are returned from `rsearch`,
656
+ // and both are valid indices.
641
657
let [ left, _, right] = unsafe { rest. split_around ( range) } ;
642
658
self . rest = left;
643
659
right
@@ -792,6 +808,8 @@ where
792
808
}
793
809
n => match self . searcher . search ( rest. borrow ( ) ) {
794
810
Some ( range) => {
811
+ // SAFETY: the start and end indices of `range` are returned from `search`,
812
+ // and both are valid indices.
795
813
let [ left, _, right] = unsafe { rest. split_around ( range) } ;
796
814
self . n = n - 1 ;
797
815
self . rest = right;
@@ -824,6 +842,8 @@ where
824
842
}
825
843
n => match self . searcher . rsearch ( rest. borrow ( ) ) {
826
844
Some ( range) => {
845
+ // SAFETY: the start and end indices of `range` are returned from `rsearch`,
846
+ // and both are valid indices.
827
847
let [ left, _, right] = unsafe { rest. split_around ( range) } ;
828
848
self . n = n - 1 ;
829
849
self . rest = left;
@@ -896,6 +916,8 @@ where
896
916
let mut searcher = from. into_searcher ( ) ;
897
917
let mut src = Span :: from ( src) ;
898
918
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.
899
921
let [ left, middle, right] = unsafe { src. split_around ( range) } ;
900
922
writer ( Span :: into ( left) ) ;
901
923
writer ( replacer ( Span :: into ( middle) ) ) ;
@@ -921,6 +943,8 @@ where
921
943
}
922
944
n -= 1 ;
923
945
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.
924
948
let [ left, middle, right] = unsafe { src. split_around ( range) } ;
925
949
writer ( Span :: into ( left) ) ;
926
950
writer ( replacer ( Span :: into ( middle) ) ) ;
0 commit comments