@@ -638,25 +638,33 @@ impl CodeMap {
638
638
fn find_width_of_character_at_span ( & self , sp : Span , forwards : bool ) -> u32 {
639
639
// Disregard malformed spans and assume a one-byte wide character.
640
640
if sp. lo ( ) >= sp. hi ( ) {
641
+ debug ! ( "find_width_of_character_at_span: early return malformed span" ) ;
641
642
return 1 ;
642
643
}
643
644
644
645
let local_begin = self . lookup_byte_offset ( sp. lo ( ) ) ;
645
646
let local_end = self . lookup_byte_offset ( sp. hi ( ) ) ;
647
+ debug ! ( "find_width_of_character_at_span: local_begin=`{:?}`, local_end=`{:?}`" ,
648
+ local_begin, local_end) ;
646
649
647
650
let start_index = local_begin. pos . to_usize ( ) ;
648
651
let end_index = local_end. pos . to_usize ( ) ;
652
+ debug ! ( "find_width_of_character_at_span: start_index=`{:?}`, end_index=`{:?}`" ,
653
+ start_index, end_index) ;
649
654
650
655
// Disregard indexes that are at the start or end of their spans, they can't fit bigger
651
656
// characters.
652
657
if ( !forwards && end_index == usize:: min_value ( ) ) ||
653
658
( forwards && start_index == usize:: max_value ( ) ) {
659
+ debug ! ( "find_width_of_character_at_span: start or end of span, cannot be multibyte" ) ;
654
660
return 1 ;
655
661
}
656
662
657
663
let source_len = ( local_begin. fm . end_pos - local_begin. fm . start_pos ) . to_usize ( ) ;
664
+ debug ! ( "find_width_of_character_at_span: source_len=`{:?}`" , source_len) ;
658
665
// Ensure indexes are also not malformed.
659
666
if start_index > end_index || end_index > source_len {
667
+ debug ! ( "find_width_of_character_at_span: source indexes are malformed" ) ;
660
668
return 1 ;
661
669
}
662
670
@@ -671,16 +679,22 @@ impl CodeMap {
671
679
} else {
672
680
return 1 ;
673
681
} ;
674
- debug ! ( "DTW start {:?} end {:?}" , start_index, end_index) ;
675
- debug ! ( "DTW snippet {:?}" , snippet) ;
682
+ debug ! ( "find_width_of_character_at_span: snippet=`{:?}`" , snippet) ;
683
+
684
+ let file_start_pos = local_begin. fm . start_pos . to_usize ( ) ;
685
+ let file_end_pos = local_begin. fm . end_pos . to_usize ( ) ;
686
+ debug ! ( "find_width_of_character_at_span: file_start_pos=`{:?}` file_end_pos=`{:?}`" ,
687
+ file_start_pos, file_end_pos) ;
676
688
677
689
let mut target = if forwards { end_index + 1 } else { end_index - 1 } ;
678
- debug ! ( "DTW initial target {:?}" , target) ;
679
- while !snippet. is_char_boundary ( target - start_index) {
690
+ debug ! ( "find_width_of_character_at_span: initial target=`{:?}`" , target) ;
691
+
692
+ while !snippet. is_char_boundary ( target - start_index)
693
+ && target >= file_start_pos && target <= file_end_pos {
680
694
target = if forwards { target + 1 } else { target - 1 } ;
681
- debug ! ( "DTW update target {:?}" , target) ;
695
+ debug ! ( "find_width_of_character_at_span: target=` {:?}` " , target) ;
682
696
}
683
- debug ! ( "DTW final target {:?}" , target) ;
697
+ debug ! ( "find_width_of_character_at_span: final target=` {:?}` " , target) ;
684
698
685
699
if forwards {
686
700
( target - end_index) as u32
0 commit comments