@@ -35,6 +35,7 @@ use crate::snippet;
3535use itertools:: FoldWhile :: { Continue , Done } ;
3636use itertools:: Itertools ;
3737use std:: fmt:: { Display , Write } ;
38+ use std:: ops:: Range ;
3839use std:: { cmp, fmt} ;
3940
4041use crate :: renderer:: { stylesheet:: Stylesheet , Margin , Style } ;
@@ -768,7 +769,7 @@ fn format_slice(
768769 has_footer : bool ,
769770 margin : Option < Margin > ,
770771) -> Vec < DisplayLine < ' _ > > {
771- let main_range = slice. annotations . first ( ) . map ( |x| x. range . 0 ) ;
772+ let main_range = slice. annotations . first ( ) . map ( |x| x. range . start ) ;
772773 let origin = slice. origin ;
773774 let need_empty_header = origin. is_some ( ) || is_first;
774775 let mut body = format_body ( slice, need_empty_header, has_footer, margin) ;
@@ -951,8 +952,8 @@ fn format_body(
951952 let source_len = slice. source . len ( ) ;
952953 if let Some ( bigger) = slice. annotations . iter ( ) . find_map ( |x| {
953954 // Allow highlighting one past the last character in the source.
954- if source_len + 1 < x. range . 1 {
955- Some ( x. range )
955+ if source_len + 1 < x. range . end {
956+ Some ( & x. range )
956957 } else {
957958 None
958959 }
@@ -1017,8 +1018,8 @@ fn format_body(
10171018 _ => DisplayAnnotationType :: from ( annotation. annotation_type ) ,
10181019 } ;
10191020 match annotation. range {
1020- ( start, _ ) if start > line_end_index => true ,
1021- ( start, end)
1021+ Range { start, .. } if start > line_end_index => true ,
1022+ Range { start, end }
10221023 if start >= line_start_index && end <= line_end_index
10231024 || start == line_end_index && end - start <= 1 =>
10241025 {
@@ -1047,7 +1048,7 @@ fn format_body(
10471048 annotation_line_count += 1 ;
10481049 false
10491050 }
1050- ( start, end)
1051+ Range { start, end }
10511052 if start >= line_start_index
10521053 && start <= line_end_index
10531054 && end > line_end_index =>
@@ -1091,7 +1092,7 @@ fn format_body(
10911092 }
10921093 true
10931094 }
1094- ( start, end) if start < line_start_index && end > line_end_index => {
1095+ Range { start, end } if start < line_start_index && end > line_end_index => {
10951096 if let DisplayLine :: Source {
10961097 ref mut inline_marks,
10971098 ..
@@ -1106,7 +1107,7 @@ fn format_body(
11061107 }
11071108 true
11081109 }
1109- ( start, end)
1110+ Range { start, end }
11101111 if start < line_start_index
11111112 && end >= line_start_index
11121113 && end <= line_end_index =>
@@ -1375,7 +1376,7 @@ mod tests {
13751376 let line_2 = "This is line 2" ;
13761377 let source = [ line_1, line_2] . join ( "\n " ) ;
13771378 // In line 2
1378- let range = ( 22 , 24 ) ;
1379+ let range = 22 .. 24 ;
13791380 let input = snippet:: Snippet {
13801381 title : None ,
13811382 footer : vec ! [ ] ,
@@ -1384,7 +1385,7 @@ mod tests {
13841385 line_start: 5402 ,
13851386 origin: None ,
13861387 annotations: vec![ snippet:: SourceAnnotation {
1387- range,
1388+ range: range . clone ( ) ,
13881389 label: "Test annotation" ,
13891390 annotation_type: snippet:: AnnotationType :: Info ,
13901391 } ] ,
@@ -1425,7 +1426,10 @@ mod tests {
14251426 style: DisplayTextStyle :: Regular ,
14261427 } ] ,
14271428 } ,
1428- range: ( range. 0 - ( line_1. len( ) + 1 ) , range. 1 - ( line_1. len( ) + 1 ) ) ,
1429+ range: (
1430+ range. start - ( line_1. len( ) + 1 ) ,
1431+ range. end - ( line_1. len( ) + 1 ) ,
1432+ ) ,
14291433 annotation_type: DisplayAnnotationType :: Info ,
14301434 annotation_part: DisplayAnnotationPart :: Standalone ,
14311435 } ,
@@ -1475,7 +1479,7 @@ mod tests {
14751479 footer : vec ! [ ] ,
14761480 slices : vec ! [ snippet:: Slice {
14771481 annotations: vec![ snippet:: SourceAnnotation {
1478- range: ( 0 , source. len( ) + 2 ) ,
1482+ range: 0 .. source. len( ) + 2 ,
14791483 label,
14801484 annotation_type: snippet:: AnnotationType :: Error ,
14811485 } ] ,
@@ -1502,7 +1506,7 @@ mod tests {
15021506 line_start: 1 ,
15031507 origin: Some ( "<current file>" ) ,
15041508 annotations: vec![ snippet:: SourceAnnotation {
1505- range: ( 19 , 23 ) ,
1509+ range: 19 .. 23 ,
15061510 label: "oops" ,
15071511 annotation_type: snippet:: AnnotationType :: Error ,
15081512 } ] ,
0 commit comments