@@ -911,12 +911,14 @@ impl SourceMap {
911
911
912
912
/// Returns a new span representing just the last character of this span.
913
913
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 ;
915
917
916
918
let width = self . find_width_of_character_at_span ( sp, false ) ;
917
919
let corrected_end_position = pos. checked_sub ( width) . unwrap_or ( pos) ;
918
920
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 ) ) ;
920
922
sp. with_lo ( end_point)
921
923
}
922
924
@@ -930,8 +932,9 @@ impl SourceMap {
930
932
if sp. is_dummy ( ) {
931
933
return sp;
932
934
}
933
- let start_of_next_point = sp. hi ( ) . 0 ;
934
935
936
+ let sp = sp. data ( ) ;
937
+ let start_of_next_point = sp. hi . 0 ;
935
938
let width = self . find_width_of_character_at_span ( sp, true ) ;
936
939
// If the width is 1, then the next span should only contain the next char besides current ending.
937
940
// However, in the case of a multibyte character, where the width != 1, the next span should
@@ -940,7 +943,7 @@ impl SourceMap {
940
943
start_of_next_point. checked_add ( width) . unwrap_or ( start_of_next_point) ;
941
944
942
945
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 )
944
947
}
945
948
946
949
/// Check whether span is followed by some specified expected string in limit scope
@@ -963,9 +966,7 @@ impl SourceMap {
963
966
/// Finds the width of the character, either before or after the end of provided span,
964
967
/// depending on the `forwards` parameter.
965
968
#[ 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 {
969
970
if sp. lo == sp. hi && !forwards {
970
971
debug ! ( "early return empty span" ) ;
971
972
return 1 ;
0 commit comments