@@ -12,7 +12,9 @@ use Destination::*;
12
12
use rustc_span:: source_map:: SourceMap ;
13
13
use rustc_span:: { FileLines , SourceFile , Span } ;
14
14
15
- use crate :: snippet:: { Annotation , AnnotationType , Line , MultilineAnnotation , Style , StyledString } ;
15
+ use crate :: snippet:: {
16
+ Annotation , AnnotationColumn , AnnotationType , Line , MultilineAnnotation , Style , StyledString ,
17
+ } ;
16
18
use crate :: styled_buffer:: StyledBuffer ;
17
19
use crate :: translation:: { to_fluent_args, Translate } ;
18
20
use crate :: {
@@ -858,7 +860,7 @@ impl EmitterWriter {
858
860
let mut short_start = true ;
859
861
for ann in & line. annotations {
860
862
if let AnnotationType :: MultilineStart ( depth) = ann. annotation_type {
861
- if source_string. chars ( ) . take ( ann. start_col ) . all ( |c| c. is_whitespace ( ) ) {
863
+ if source_string. chars ( ) . take ( ann. start_col . display ) . all ( |c| c. is_whitespace ( ) ) {
862
864
let style = if ann. is_primary {
863
865
Style :: UnderlinePrimary
864
866
} else {
@@ -1093,15 +1095,15 @@ impl EmitterWriter {
1093
1095
'_' ,
1094
1096
line_offset + pos,
1095
1097
width_offset + depth,
1096
- ( code_offset + annotation. start_col ) . saturating_sub ( left) ,
1098
+ ( code_offset + annotation. start_col . display ) . saturating_sub ( left) ,
1097
1099
style,
1098
1100
) ;
1099
1101
}
1100
1102
_ if self . teach => {
1101
1103
buffer. set_style_range (
1102
1104
line_offset,
1103
- ( code_offset + annotation. start_col ) . saturating_sub ( left) ,
1104
- ( code_offset + annotation. end_col ) . saturating_sub ( left) ,
1105
+ ( code_offset + annotation. start_col . display ) . saturating_sub ( left) ,
1106
+ ( code_offset + annotation. end_col . display ) . saturating_sub ( left) ,
1105
1107
style,
1106
1108
annotation. is_primary ,
1107
1109
) ;
@@ -1133,7 +1135,7 @@ impl EmitterWriter {
1133
1135
for p in line_offset + 1 ..=line_offset + pos {
1134
1136
buffer. putc (
1135
1137
p,
1136
- ( code_offset + annotation. start_col ) . saturating_sub ( left) ,
1138
+ ( code_offset + annotation. start_col . display ) . saturating_sub ( left) ,
1137
1139
'|' ,
1138
1140
style,
1139
1141
) ;
@@ -1169,9 +1171,9 @@ impl EmitterWriter {
1169
1171
let style =
1170
1172
if annotation. is_primary { Style :: LabelPrimary } else { Style :: LabelSecondary } ;
1171
1173
let ( pos, col) = if pos == 0 {
1172
- ( pos + 1 , ( annotation. end_col + 1 ) . saturating_sub ( left) )
1174
+ ( pos + 1 , ( annotation. end_col . display + 1 ) . saturating_sub ( left) )
1173
1175
} else {
1174
- ( pos + 2 , annotation. start_col . saturating_sub ( left) )
1176
+ ( pos + 2 , annotation. start_col . display . saturating_sub ( left) )
1175
1177
} ;
1176
1178
if let Some ( ref label) = annotation. label {
1177
1179
buffer. puts ( line_offset + pos, code_offset + col, label, style) ;
@@ -1208,7 +1210,7 @@ impl EmitterWriter {
1208
1210
} else {
1209
1211
( '-' , Style :: UnderlineSecondary )
1210
1212
} ;
1211
- for p in annotation. start_col .. annotation. end_col {
1213
+ for p in annotation. start_col . display .. annotation. end_col . display {
1212
1214
buffer. putc (
1213
1215
line_offset + 1 ,
1214
1216
( code_offset + p) . saturating_sub ( left) ,
@@ -1459,7 +1461,7 @@ impl EmitterWriter {
1459
1461
& annotated_file. file. name,
1460
1462
line. line_index
1461
1463
) ,
1462
- annotations[ 0 ] . start_col + 1 ,
1464
+ annotations[ 0 ] . start_col. file + 1 ,
1463
1465
) ,
1464
1466
Style :: LineAndColumn ,
1465
1467
) ;
@@ -1546,7 +1548,7 @@ impl EmitterWriter {
1546
1548
buffer. prepend ( buffer_msg_line_offset + 1 , "::: " , Style :: LineNumber ) ;
1547
1549
let loc = if let Some ( first_line) = annotated_file. lines . first ( ) {
1548
1550
let col = if let Some ( first_annotation) = first_line. annotations . first ( ) {
1549
- format ! ( ":{}" , first_annotation. start_col + 1 )
1551
+ format ! ( ":{}" , first_annotation. start_col. file + 1 )
1550
1552
} else {
1551
1553
String :: new ( )
1552
1554
} ;
@@ -1607,8 +1609,8 @@ impl EmitterWriter {
1607
1609
let mut span_left_margin = usize:: MAX ;
1608
1610
for line in & annotated_file. lines {
1609
1611
for ann in & line. annotations {
1610
- span_left_margin = min ( span_left_margin, ann. start_col ) ;
1611
- span_left_margin = min ( span_left_margin, ann. end_col ) ;
1612
+ span_left_margin = min ( span_left_margin, ann. start_col . display ) ;
1613
+ span_left_margin = min ( span_left_margin, ann. end_col . display ) ;
1612
1614
}
1613
1615
}
1614
1616
if span_left_margin == usize:: MAX {
@@ -1625,11 +1627,12 @@ impl EmitterWriter {
1625
1627
annotated_file. file . get_line ( line. line_index - 1 ) . map_or ( 0 , |s| s. len ( ) ) ,
1626
1628
) ;
1627
1629
for ann in & line. annotations {
1628
- span_right_margin = max ( span_right_margin, ann. start_col ) ;
1629
- span_right_margin = max ( span_right_margin, ann. end_col ) ;
1630
+ span_right_margin = max ( span_right_margin, ann. start_col . display ) ;
1631
+ span_right_margin = max ( span_right_margin, ann. end_col . display ) ;
1630
1632
// FIXME: account for labels not in the same line
1631
1633
let label_right = ann. label . as_ref ( ) . map_or ( 0 , |l| l. len ( ) + 1 ) ;
1632
- label_right_margin = max ( label_right_margin, ann. end_col + label_right) ;
1634
+ label_right_margin =
1635
+ max ( label_right_margin, ann. end_col . display + label_right) ;
1633
1636
}
1634
1637
}
1635
1638
@@ -2352,17 +2355,17 @@ impl FileWithAnnotatedLines {
2352
2355
depth : 1 ,
2353
2356
line_start : lo. line ,
2354
2357
line_end : hi. line ,
2355
- start_col : lo . col_display ,
2356
- end_col : hi . col_display ,
2358
+ start_col : AnnotationColumn :: from_loc ( & lo ) ,
2359
+ end_col : AnnotationColumn :: from_loc ( & hi ) ,
2357
2360
is_primary,
2358
2361
label,
2359
2362
overlaps_exactly : false ,
2360
2363
} ;
2361
2364
multiline_annotations. push ( ( lo. file , ml) ) ;
2362
2365
} else {
2363
2366
let ann = Annotation {
2364
- start_col : lo . col_display ,
2365
- end_col : hi . col_display ,
2367
+ start_col : AnnotationColumn :: from_loc ( & lo ) ,
2368
+ end_col : AnnotationColumn :: from_loc ( & hi ) ,
2366
2369
is_primary,
2367
2370
label,
2368
2371
annotation_type : AnnotationType :: Singleline ,
@@ -2551,7 +2554,13 @@ fn num_overlap(
2551
2554
( b_start..b_end + extra) . contains ( & a_start) || ( a_start..a_end + extra) . contains ( & b_start)
2552
2555
}
2553
2556
fn overlaps ( a1 : & Annotation , a2 : & Annotation , padding : usize ) -> bool {
2554
- num_overlap ( a1. start_col , a1. end_col + padding, a2. start_col , a2. end_col , false )
2557
+ num_overlap (
2558
+ a1. start_col . display ,
2559
+ a1. end_col . display + padding,
2560
+ a2. start_col . display ,
2561
+ a2. end_col . display ,
2562
+ false ,
2563
+ )
2555
2564
}
2556
2565
2557
2566
fn emit_to_destination (
0 commit comments