@@ -22,23 +22,13 @@ use crate::position;
2222#[ derive( Clone , Copy ) ]
2323pub struct Span < ' i > {
2424 input : & ' i str ,
25- /// # Safety
26- ///
27- /// Must be a valid character boundary index into `input`.
2825 start : usize ,
29- /// # Safety
30- ///
31- /// Must be a valid character boundary index into `input`.
3226 end : usize ,
3327}
3428
3529impl < ' i > Span < ' i > {
3630 /// Create a new `Span` without checking invariants. (Checked with `debug_assertions`.)
37- ///
38- /// # Safety
39- ///
40- /// `input[start..end]` must be a valid subslice; that is, said indexing should not panic.
41- pub ( crate ) unsafe fn new_unchecked ( input : & str , start : usize , end : usize ) -> Span < ' _ > {
31+ pub ( crate ) fn new_internal ( input : & str , start : usize , end : usize ) -> Span < ' _ > {
4232 debug_assert ! ( input. get( start..end) . is_some( ) ) ;
4333 Span { input, start, end }
4434 }
@@ -144,8 +134,7 @@ impl<'i> Span<'i> {
144134 /// ```
145135 #[ inline]
146136 pub fn start_pos ( & self ) -> position:: Position < ' i > {
147- // Span's start position is always a UTF-8 border.
148- unsafe { position:: Position :: new_unchecked ( self . input , self . start ) }
137+ position:: Position :: new_internal ( self . input , self . start )
149138 }
150139
151140 /// Returns the `Span`'s end `Position`.
@@ -163,8 +152,7 @@ impl<'i> Span<'i> {
163152 /// ```
164153 #[ inline]
165154 pub fn end_pos ( & self ) -> position:: Position < ' i > {
166- // Span's end position is always a UTF-8 border.
167- unsafe { position:: Position :: new_unchecked ( self . input , self . end ) }
155+ position:: Position :: new_internal ( self . input , self . end )
168156 }
169157
170158 /// Splits the `Span` into a pair of `Position`s.
@@ -182,9 +170,8 @@ impl<'i> Span<'i> {
182170 /// ```
183171 #[ inline]
184172 pub fn split ( self ) -> ( position:: Position < ' i > , position:: Position < ' i > ) {
185- // Span's start and end positions are always a UTF-8 borders.
186- let pos1 = unsafe { position:: Position :: new_unchecked ( self . input , self . start ) } ;
187- let pos2 = unsafe { position:: Position :: new_unchecked ( self . input , self . end ) } ;
173+ let pos1 = position:: Position :: new_internal ( self . input , self . start ) ;
174+ let pos2 = position:: Position :: new_internal ( self . input , self . end ) ;
188175
189176 ( pos1, pos2)
190177 }
0 commit comments