@@ -911,12 +911,14 @@ impl SourceMap {
911911
912912 /// Returns a new span representing just the last character of this span.
913913 pub fn end_point ( & self , sp : Span ) -> Span {
914- let pos = sp. hi ( ) . 0 ;
914+ // We restrict the current span, so we cannot look around. Using the untracked data is ok.
915+ let sp = sp. data_untracked ( ) ;
916+ let pos = sp. hi . 0 ;
915917
916918 let width = self . find_width_of_character_at_span ( sp, false ) ;
917919 let corrected_end_position = pos. checked_sub ( width) . unwrap_or ( pos) ;
918920
919- let end_point = BytePos ( cmp:: max ( corrected_end_position, sp. lo ( ) . 0 ) ) ;
921+ let end_point = BytePos ( cmp:: max ( corrected_end_position, sp. lo . 0 ) ) ;
920922 sp. with_lo ( end_point)
921923 }
922924
@@ -930,8 +932,9 @@ impl SourceMap {
930932 if sp. is_dummy ( ) {
931933 return sp;
932934 }
933- let start_of_next_point = sp. hi ( ) . 0 ;
934935
936+ let sp = sp. data ( ) ;
937+ let start_of_next_point = sp. hi . 0 ;
935938 let width = self . find_width_of_character_at_span ( sp, true ) ;
936939 // If the width is 1, then the next span should only contain the next char besides current ending.
937940 // However, in the case of a multibyte character, where the width != 1, the next span should
@@ -940,7 +943,7 @@ impl SourceMap {
940943 start_of_next_point. checked_add ( width) . unwrap_or ( start_of_next_point) ;
941944
942945 let end_of_next_point = BytePos ( cmp:: max ( start_of_next_point + 1 , end_of_next_point) ) ;
943- Span :: new ( BytePos ( start_of_next_point) , end_of_next_point, sp. ctxt ( ) , None )
946+ Span :: new ( BytePos ( start_of_next_point) , end_of_next_point, sp. ctxt , None )
944947 }
945948
946949 /// Check whether span is followed by some specified expected string in limit scope
@@ -963,9 +966,7 @@ impl SourceMap {
963966 /// Finds the width of the character, either before or after the end of provided span,
964967 /// depending on the `forwards` parameter.
965968 #[ instrument( skip( self , sp) ) ]
966- fn find_width_of_character_at_span ( & self , sp : Span , forwards : bool ) -> u32 {
967- let sp = sp. data ( ) ;
968-
969+ fn find_width_of_character_at_span ( & self , sp : SpanData , forwards : bool ) -> u32 {
969970 if sp. lo == sp. hi && !forwards {
970971 debug ! ( "early return empty span" ) ;
971972 return 1 ;
0 commit comments