File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -934,14 +934,15 @@ fn format_body(
934934) -> Vec < DisplayLine < ' _ > > {
935935 let source_len = slice. source . chars ( ) . count ( ) ;
936936 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 {
938939 Some ( x. range )
939940 } else {
940941 None
941942 }
942943 } ) {
943944 panic ! (
944- "SourceAnnotation range `{:?}` is bigger than source length `{}`" ,
945+ "SourceAnnotation range `{:?}` is beyond the end of buffer `{}`" ,
945946 bigger, source_len
946947 )
947948 }
@@ -1479,7 +1480,7 @@ mod tests {
14791480 footer : vec ! [ ] ,
14801481 slices : vec ! [ snippet:: Slice {
14811482 annotations: vec![ snippet:: SourceAnnotation {
1482- range: ( 0 , source. len( ) + 1 ) ,
1483+ range: ( 0 , source. len( ) + 2 ) ,
14831484 label,
14841485 annotation_type: snippet:: AnnotationType :: Error ,
14851486 } ] ,
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