@@ -22,7 +22,7 @@ use rustc_error_messages::{FluentArgs, SpanLabel};
22
22
use rustc_lint_defs:: pluralize;
23
23
use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
24
24
use rustc_span:: source_map:: SourceMap ;
25
- use rustc_span:: { FileLines , FileName , SourceFile , Span , char_width} ;
25
+ use rustc_span:: { FileLines , FileName , SourceFile , Span , char_width, str_width } ;
26
26
use termcolor:: { Buffer , BufferWriter , Color , ColorChoice , ColorSpec , StandardStream , WriteColor } ;
27
27
use tracing:: { debug, instrument, trace, warn} ;
28
28
@@ -113,8 +113,12 @@ impl Margin {
113
113
fn was_cut_right ( & self , line_len : usize ) -> bool {
114
114
let right =
115
115
if self . computed_right == self . span_right || self . computed_right == self . label_right {
116
+ // FIXME: This comment refers to the only callsite of this method.
117
+ // Rephrase it or refactor it, so it can stand on its own.
116
118
// Account for the "..." padding given above. Otherwise we end up with code lines
117
119
// that do fit but end in "..." as if they were trimmed.
120
+ // FIXME: Don't hard-code this offset. Is this meant to represent
121
+ // `2 * str_width(self.margin())`?
118
122
self . computed_right - 6
119
123
} else {
120
124
self . computed_right
@@ -673,6 +677,7 @@ impl HumanEmitter {
673
677
// Create the source line we will highlight.
674
678
let left = margin. left ( line_len) ;
675
679
let right = margin. right ( line_len) ;
680
+ // FIXME: The following code looks fishy. See #132860.
676
681
// On long lines, we strip the source line, accounting for unicode.
677
682
let mut taken = 0 ;
678
683
let code: String = source_string
@@ -695,7 +700,7 @@ impl HumanEmitter {
695
700
buffer. puts ( line_offset, code_offset, placeholder, Style :: LineNumber ) ;
696
701
}
697
702
if margin. was_cut_right ( line_len) {
698
- let padding: usize = placeholder . chars ( ) . map ( |ch| char_width ( ch ) ) . sum ( ) ;
703
+ let padding = str_width ( placeholder ) ;
699
704
// We have stripped some code after the rightmost span end, make it clear we did so.
700
705
buffer. puts ( line_offset, code_offset + taken - padding, placeholder, Style :: LineNumber ) ;
701
706
}
@@ -744,6 +749,7 @@ impl HumanEmitter {
744
749
// Left trim
745
750
let left = margin. left ( source_string. len ( ) ) ;
746
751
752
+ // FIXME: This looks fishy. See #132860.
747
753
// Account for unicode characters of width !=0 that were removed.
748
754
let left = source_string. chars ( ) . take ( left) . map ( |ch| char_width ( ch) ) . sum ( ) ;
749
755
@@ -1068,21 +1074,15 @@ impl HumanEmitter {
1068
1074
1069
1075
if pos > 1 && ( annotation. has_label ( ) || annotation. takes_space ( ) ) {
1070
1076
for p in line_offset + 1 ..=line_offset + pos {
1071
- if let AnnotationType :: MultilineLine ( _) = annotation. annotation_type {
1072
- buffer. putc (
1073
- p,
1074
- ( code_offset + annotation. start_col . display ) . saturating_sub ( left) ,
1075
- underline. multiline_vertical ,
1076
- underline. style ,
1077
- ) ;
1078
- } else {
1079
- buffer. putc (
1080
- p,
1081
- ( code_offset + annotation. start_col . display ) . saturating_sub ( left) ,
1082
- underline. vertical_text_line ,
1083
- underline. style ,
1084
- ) ;
1085
- }
1077
+ buffer. putc (
1078
+ p,
1079
+ ( code_offset + annotation. start_col . display ) . saturating_sub ( left) ,
1080
+ match annotation. annotation_style {
1081
+ AnnotationType :: MultilineLine ( _) => underline. multiline_vertical ,
1082
+ _ => underline. vertical_text_line ,
1083
+ } ,
1084
+ underline. style ,
1085
+ ) ;
1086
1086
}
1087
1087
if let AnnotationType :: MultilineStart ( _) = annotation. annotation_type {
1088
1088
buffer. putc (
@@ -2134,7 +2134,7 @@ impl HumanEmitter {
2134
2134
}
2135
2135
2136
2136
let placeholder = self . margin ( ) ;
2137
- let padding: usize = placeholder . chars ( ) . map ( |ch| char_width ( ch ) ) . sum ( ) ;
2137
+ let padding = str_width ( placeholder ) ;
2138
2138
buffer. puts (
2139
2139
row_num,
2140
2140
max_line_num_len. saturating_sub ( padding) ,
@@ -2224,11 +2224,11 @@ impl HumanEmitter {
2224
2224
} ;
2225
2225
// ...or trailing spaces. Account for substitutions containing unicode
2226
2226
// characters.
2227
- let sub_len: usize =
2228
- if is_whitespace_addition { & part. snippet } else { part . snippet . trim ( ) }
2229
- . chars ( )
2230
- . map ( |ch| char_width ( ch ) )
2231
- . sum ( ) ;
2227
+ let sub_len: usize = str_width ( if is_whitespace_addition {
2228
+ & part. snippet
2229
+ } else {
2230
+ part . snippet . trim ( )
2231
+ } ) ;
2232
2232
2233
2233
let offset: isize = offsets
2234
2234
. iter ( )
@@ -2266,8 +2266,7 @@ impl HumanEmitter {
2266
2266
}
2267
2267
2268
2268
// length of the code after substitution
2269
- let full_sub_len =
2270
- part. snippet . chars ( ) . map ( |ch| char_width ( ch) ) . sum :: < usize > ( ) as isize ;
2269
+ let full_sub_len = str_width ( & part. snippet ) as isize ;
2271
2270
2272
2271
// length of the code to be substituted
2273
2272
let snippet_len = span_end_pos as isize - span_start_pos as isize ;
@@ -2282,7 +2281,7 @@ impl HumanEmitter {
2282
2281
// if we elided some lines, add an ellipsis
2283
2282
if lines. next ( ) . is_some ( ) {
2284
2283
let placeholder = self . margin ( ) ;
2285
- let padding: usize = placeholder . chars ( ) . map ( |ch| char_width ( ch ) ) . sum ( ) ;
2284
+ let padding = str_width ( placeholder ) ;
2286
2285
buffer. puts (
2287
2286
row_num,
2288
2287
max_line_num_len. saturating_sub ( padding) ,
0 commit comments