@@ -776,16 +776,23 @@ impl<'parser> Parser<'parser> {
776776 min_context_len : usize ,
777777 ellipsis : & str ,
778778 ) -> ParserErrorContext {
779+ // `indicator_start` is a 0-based char position
780+ let indicator_start = self . column_number - 1 ;
781+
782+ let error_line_len = self . current_line . chars ( ) . count ( ) ;
783+
779784 let indicator_len = if self . line_number == self . next_line_number {
780- std:: cmp:: max ( self . next_column_number - self . column_number , 1 )
785+ std:: cmp:: max (
786+ std:: cmp:: min (
787+ self . next_column_number - self . column_number ,
788+ error_line_len - indicator_start,
789+ ) ,
790+ 1 ,
791+ )
781792 } else {
782793 1
783794 } ;
784795
785- // `indicator_start` is a 0-based char position
786- let indicator_start = self . column_number - 1 ;
787-
788- let error_line_len = self . current_line . chars ( ) . count ( ) ;
789796 if error_line_len <= max_error_line_len {
790797 ParserErrorContext :: new ( self . current_line . to_owned ( ) , indicator_start, indicator_len)
791798 } else {
@@ -852,7 +859,14 @@ fn trim_error_line_and_indicator(
852859 assert ! ( max_error_line_len > ellipsis_len) ;
853860 assert ! ( max_error_line_len < error_line_len) ;
854861 assert ! ( indicator_start <= error_line_len) ;
855- assert ! ( indicator_len == 1 || ( indicator_start + indicator_len) <= error_line_len) ;
862+ assert ! (
863+ indicator_len == 1 || ( indicator_start + indicator_len) <= error_line_len,
864+ "indicator_start={}, indicator_len={}, error_line_len={}\n {}" ,
865+ indicator_start,
866+ indicator_len,
867+ error_line_len,
868+ error_line
869+ ) ;
856870
857871 indicator_len = std:: cmp:: min ( indicator_len, max_error_line_len) ;
858872
0 commit comments