File tree 1 file changed +9
-5
lines changed
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -621,13 +621,17 @@ impl CodeMap {
621
621
622
622
/// Returns a new span representing the next character after the end-point of this span
623
623
pub fn next_point ( & self , sp : Span ) -> Span {
624
- let pos = sp. lo ( ) . 0 ;
624
+ let start_of_next_point = sp. hi ( ) . 0 ;
625
625
626
626
let width = self . find_width_of_character_at_span ( sp, true ) ;
627
- let corrected_next_position = pos. checked_add ( width) . unwrap_or ( pos) ;
628
-
629
- let next_point = BytePos ( cmp:: max ( sp. hi ( ) . 0 , corrected_next_position) ) ;
630
- Span :: new ( next_point, next_point, sp. ctxt ( ) )
627
+ // If the width is 1, then the next span should point to the same `lo` and `hi`. However,
628
+ // in the case of a multibyte character, where the width != 1, the next span should
629
+ // span multiple bytes to include the whole character.
630
+ let end_of_next_point = start_of_next_point. checked_add (
631
+ width - 1 ) . unwrap_or ( start_of_next_point) ;
632
+
633
+ let end_of_next_point = BytePos ( cmp:: max ( sp. lo ( ) . 0 + 1 , end_of_next_point) ) ;
634
+ Span :: new ( BytePos ( start_of_next_point) , end_of_next_point, sp. ctxt ( ) )
631
635
}
632
636
633
637
/// Finds the width of a character, either before or after the provided span.
You can’t perform that action at this time.
0 commit comments