File tree 3 files changed +22
-3
lines changed
3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -934,14 +934,15 @@ fn format_body(
934
934
) -> Vec < DisplayLine < ' _ > > {
935
935
let source_len = slice. source . chars ( ) . count ( ) ;
936
936
if let Some ( bigger) = slice. annotations . iter ( ) . find_map ( |x| {
937
- if source_len < x. range . 1 {
937
+ // Allow highlighting one past the last character in the source.
938
+ if source_len + 1 < x. range . 1 {
938
939
Some ( x. range )
939
940
} else {
940
941
None
941
942
}
942
943
} ) {
943
944
panic ! (
944
- "SourceAnnotation range `{:?}` is bigger than source length `{}`" ,
945
+ "SourceAnnotation range `{:?}` is beyond the end of buffer `{}`" ,
945
946
bigger, source_len
946
947
)
947
948
}
@@ -1479,7 +1480,7 @@ mod tests {
1479
1480
footer : vec ! [ ] ,
1480
1481
slices : vec ! [ snippet:: Slice {
1481
1482
annotations: vec![ snippet:: SourceAnnotation {
1482
- range: ( 0 , source. len( ) + 1 ) ,
1483
+ range: ( 0 , source. len( ) + 2 ) ,
1483
1484
label,
1484
1485
annotation_type: snippet:: AnnotationType :: Error ,
1485
1486
} ] ,
Original file line number Diff line number Diff line change
1
+ [snippet .title ]
2
+ label = " expected `.`, `=`"
3
+ annotation_type = " Error"
4
+
5
+ [[snippet .slices ]]
6
+ source = " asdf"
7
+ line_start = 1
8
+ origin = " Cargo.toml"
9
+ [[snippet .slices .annotations ]]
10
+ label = " "
11
+ annotation_type = " Error"
12
+ range = [4 , 5 ]
Original file line number Diff line number Diff line change
1
+ error: expected `.`, `=`
2
+ --> Cargo.toml:1:5
3
+ |
4
+ 1 | asdf
5
+ | ^
6
+ |
You can’t perform that action at this time.
0 commit comments