@@ -12,7 +12,9 @@ use Destination::*;
1212use rustc_span:: source_map:: SourceMap ;
1313use rustc_span:: { FileLines , SourceFile , Span } ;
1414
15- use crate :: snippet:: { Annotation , AnnotationType , Line , MultilineAnnotation , Style , StyledString } ;
15+ use crate :: snippet:: {
16+ Annotation , AnnotationColumn , AnnotationType , Line , MultilineAnnotation , Style , StyledString ,
17+ } ;
1618use crate :: styled_buffer:: StyledBuffer ;
1719use crate :: translation:: { to_fluent_args, Translate } ;
1820use crate :: {
@@ -858,7 +860,7 @@ impl EmitterWriter {
858860 let mut short_start = true ;
859861 for ann in & line. annotations {
860862 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 ( ) ) {
862864 let style = if ann. is_primary {
863865 Style :: UnderlinePrimary
864866 } else {
@@ -1093,15 +1095,15 @@ impl EmitterWriter {
10931095 '_' ,
10941096 line_offset + pos,
10951097 width_offset + depth,
1096- ( code_offset + annotation. start_col ) . saturating_sub ( left) ,
1098+ ( code_offset + annotation. start_col . display ) . saturating_sub ( left) ,
10971099 style,
10981100 ) ;
10991101 }
11001102 _ if self . teach => {
11011103 buffer. set_style_range (
11021104 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) ,
11051107 style,
11061108 annotation. is_primary ,
11071109 ) ;
@@ -1133,7 +1135,7 @@ impl EmitterWriter {
11331135 for p in line_offset + 1 ..=line_offset + pos {
11341136 buffer. putc (
11351137 p,
1136- ( code_offset + annotation. start_col ) . saturating_sub ( left) ,
1138+ ( code_offset + annotation. start_col . display ) . saturating_sub ( left) ,
11371139 '|' ,
11381140 style,
11391141 ) ;
@@ -1169,9 +1171,9 @@ impl EmitterWriter {
11691171 let style =
11701172 if annotation. is_primary { Style :: LabelPrimary } else { Style :: LabelSecondary } ;
11711173 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) )
11731175 } else {
1174- ( pos + 2 , annotation. start_col . saturating_sub ( left) )
1176+ ( pos + 2 , annotation. start_col . display . saturating_sub ( left) )
11751177 } ;
11761178 if let Some ( ref label) = annotation. label {
11771179 buffer. puts ( line_offset + pos, code_offset + col, label, style) ;
@@ -1208,7 +1210,7 @@ impl EmitterWriter {
12081210 } else {
12091211 ( '-' , Style :: UnderlineSecondary )
12101212 } ;
1211- for p in annotation. start_col .. annotation. end_col {
1213+ for p in annotation. start_col . display .. annotation. end_col . display {
12121214 buffer. putc (
12131215 line_offset + 1 ,
12141216 ( code_offset + p) . saturating_sub ( left) ,
@@ -1459,7 +1461,7 @@ impl EmitterWriter {
14591461 & annotated_file. file. name,
14601462 line. line_index
14611463 ) ,
1462- annotations[ 0 ] . start_col + 1 ,
1464+ annotations[ 0 ] . start_col. file + 1 ,
14631465 ) ,
14641466 Style :: LineAndColumn ,
14651467 ) ;
@@ -1546,7 +1548,7 @@ impl EmitterWriter {
15461548 buffer. prepend ( buffer_msg_line_offset + 1 , "::: " , Style :: LineNumber ) ;
15471549 let loc = if let Some ( first_line) = annotated_file. lines . first ( ) {
15481550 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 )
15501552 } else {
15511553 String :: new ( )
15521554 } ;
@@ -1607,8 +1609,8 @@ impl EmitterWriter {
16071609 let mut span_left_margin = usize:: MAX ;
16081610 for line in & annotated_file. lines {
16091611 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 ) ;
16121614 }
16131615 }
16141616 if span_left_margin == usize:: MAX {
@@ -1625,11 +1627,12 @@ impl EmitterWriter {
16251627 annotated_file. file . get_line ( line. line_index - 1 ) . map_or ( 0 , |s| s. len ( ) ) ,
16261628 ) ;
16271629 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 ) ;
16301632 // FIXME: account for labels not in the same line
16311633 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) ;
16331636 }
16341637 }
16351638
@@ -2352,17 +2355,17 @@ impl FileWithAnnotatedLines {
23522355 depth : 1 ,
23532356 line_start : lo. line ,
23542357 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 ) ,
23572360 is_primary,
23582361 label,
23592362 overlaps_exactly : false ,
23602363 } ;
23612364 multiline_annotations. push ( ( lo. file , ml) ) ;
23622365 } else {
23632366 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 ) ,
23662369 is_primary,
23672370 label,
23682371 annotation_type : AnnotationType :: Singleline ,
@@ -2551,7 +2554,13 @@ fn num_overlap(
25512554 ( b_start..b_end + extra) . contains ( & a_start) || ( a_start..a_end + extra) . contains ( & b_start)
25522555}
25532556fn 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+ )
25552564}
25562565
25572566fn emit_to_destination (
0 commit comments