@@ -35,6 +35,7 @@ use crate::snippet;
35
35
use itertools:: FoldWhile :: { Continue , Done } ;
36
36
use itertools:: Itertools ;
37
37
use std:: fmt:: { Display , Write } ;
38
+ use std:: ops:: Range ;
38
39
use std:: { cmp, fmt} ;
39
40
40
41
use crate :: renderer:: { stylesheet:: Stylesheet , Margin , Style } ;
@@ -768,7 +769,7 @@ fn format_slice(
768
769
has_footer : bool ,
769
770
margin : Option < Margin > ,
770
771
) -> 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 ) ;
772
773
let origin = slice. origin ;
773
774
let need_empty_header = origin. is_some ( ) || is_first;
774
775
let mut body = format_body ( slice, need_empty_header, has_footer, margin) ;
@@ -951,8 +952,8 @@ fn format_body(
951
952
let source_len = slice. source . len ( ) ;
952
953
if let Some ( bigger) = slice. annotations . iter ( ) . find_map ( |x| {
953
954
// 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 )
956
957
} else {
957
958
None
958
959
}
@@ -1017,8 +1018,8 @@ fn format_body(
1017
1018
_ => DisplayAnnotationType :: from ( annotation. annotation_type ) ,
1018
1019
} ;
1019
1020
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 }
1022
1023
if start >= line_start_index && end <= line_end_index
1023
1024
|| start == line_end_index && end - start <= 1 =>
1024
1025
{
@@ -1047,7 +1048,7 @@ fn format_body(
1047
1048
annotation_line_count += 1 ;
1048
1049
false
1049
1050
}
1050
- ( start, end)
1051
+ Range { start, end }
1051
1052
if start >= line_start_index
1052
1053
&& start <= line_end_index
1053
1054
&& end > line_end_index =>
@@ -1091,7 +1092,7 @@ fn format_body(
1091
1092
}
1092
1093
true
1093
1094
}
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 => {
1095
1096
if let DisplayLine :: Source {
1096
1097
ref mut inline_marks,
1097
1098
..
@@ -1106,7 +1107,7 @@ fn format_body(
1106
1107
}
1107
1108
true
1108
1109
}
1109
- ( start, end)
1110
+ Range { start, end }
1110
1111
if start < line_start_index
1111
1112
&& end >= line_start_index
1112
1113
&& end <= line_end_index =>
@@ -1375,7 +1376,7 @@ mod tests {
1375
1376
let line_2 = "This is line 2" ;
1376
1377
let source = [ line_1, line_2] . join ( "\n " ) ;
1377
1378
// In line 2
1378
- let range = ( 22 , 24 ) ;
1379
+ let range = 22 .. 24 ;
1379
1380
let input = snippet:: Snippet {
1380
1381
title : None ,
1381
1382
footer : vec ! [ ] ,
@@ -1384,7 +1385,7 @@ mod tests {
1384
1385
line_start: 5402 ,
1385
1386
origin: None ,
1386
1387
annotations: vec![ snippet:: SourceAnnotation {
1387
- range,
1388
+ range: range . clone ( ) ,
1388
1389
label: "Test annotation" ,
1389
1390
annotation_type: snippet:: AnnotationType :: Info ,
1390
1391
} ] ,
@@ -1425,7 +1426,10 @@ mod tests {
1425
1426
style: DisplayTextStyle :: Regular ,
1426
1427
} ] ,
1427
1428
} ,
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
+ ) ,
1429
1433
annotation_type: DisplayAnnotationType :: Info ,
1430
1434
annotation_part: DisplayAnnotationPart :: Standalone ,
1431
1435
} ,
@@ -1475,7 +1479,7 @@ mod tests {
1475
1479
footer : vec ! [ ] ,
1476
1480
slices : vec ! [ snippet:: Slice {
1477
1481
annotations: vec![ snippet:: SourceAnnotation {
1478
- range: ( 0 , source. len( ) + 2 ) ,
1482
+ range: 0 .. source. len( ) + 2 ,
1479
1483
label,
1480
1484
annotation_type: snippet:: AnnotationType :: Error ,
1481
1485
} ] ,
@@ -1502,7 +1506,7 @@ mod tests {
1502
1506
line_start: 1 ,
1503
1507
origin: Some ( "<current file>" ) ,
1504
1508
annotations: vec![ snippet:: SourceAnnotation {
1505
- range: ( 19 , 23 ) ,
1509
+ range: 19 .. 23 ,
1506
1510
label: "oops" ,
1507
1511
annotation_type: snippet:: AnnotationType :: Error ,
1508
1512
} ] ,
0 commit comments