@@ -22,7 +22,7 @@ use rustc_error_messages::{FluentArgs, SpanLabel};
2222use rustc_lint_defs:: pluralize;
2323use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
2424use 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 } ;
2626use termcolor:: { Buffer , BufferWriter , Color , ColorChoice , ColorSpec , StandardStream , WriteColor } ;
2727use tracing:: { debug, instrument, trace, warn} ;
2828
@@ -113,8 +113,12 @@ impl Margin {
113113 fn was_cut_right ( & self , line_len : usize ) -> bool {
114114 let right =
115115 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.
116118 // Account for the "..." padding given above. Otherwise we end up with code lines
117119 // 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())`?
118122 self . computed_right - 6
119123 } else {
120124 self . computed_right
@@ -673,6 +677,7 @@ impl HumanEmitter {
673677 // Create the source line we will highlight.
674678 let left = margin. left ( line_len) ;
675679 let right = margin. right ( line_len) ;
680+ // FIXME: The following code looks fishy. See #132860.
676681 // On long lines, we strip the source line, accounting for unicode.
677682 let mut taken = 0 ;
678683 let code: String = source_string
@@ -695,7 +700,7 @@ impl HumanEmitter {
695700 buffer. puts ( line_offset, code_offset, placeholder, Style :: LineNumber ) ;
696701 }
697702 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 ) ;
699704 // We have stripped some code after the rightmost span end, make it clear we did so.
700705 buffer. puts ( line_offset, code_offset + taken - padding, placeholder, Style :: LineNumber ) ;
701706 }
@@ -744,6 +749,7 @@ impl HumanEmitter {
744749 // Left trim
745750 let left = margin. left ( source_string. len ( ) ) ;
746751
752+ // FIXME: This looks fishy. See #132860.
747753 // Account for unicode characters of width !=0 that were removed.
748754 let left = source_string. chars ( ) . take ( left) . map ( |ch| char_width ( ch) ) . sum ( ) ;
749755
@@ -1068,21 +1074,15 @@ impl HumanEmitter {
10681074
10691075 if pos > 1 && ( annotation. has_label ( ) || annotation. takes_space ( ) ) {
10701076 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_type {
1081+ AnnotationType :: MultilineLine ( _) => underline. multiline_vertical ,
1082+ _ => underline. vertical_text_line ,
1083+ } ,
1084+ underline. style ,
1085+ ) ;
10861086 }
10871087 if let AnnotationType :: MultilineStart ( _) = annotation. annotation_type {
10881088 buffer. putc (
@@ -2134,7 +2134,7 @@ impl HumanEmitter {
21342134 }
21352135
21362136 let placeholder = self . margin ( ) ;
2137- let padding: usize = placeholder . chars ( ) . map ( |ch| char_width ( ch ) ) . sum ( ) ;
2137+ let padding = str_width ( placeholder ) ;
21382138 buffer. puts (
21392139 row_num,
21402140 max_line_num_len. saturating_sub ( padding) ,
@@ -2224,11 +2224,11 @@ impl HumanEmitter {
22242224 } ;
22252225 // ...or trailing spaces. Account for substitutions containing unicode
22262226 // 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+ } ) ;
22322232
22332233 let offset: isize = offsets
22342234 . iter ( )
@@ -2266,8 +2266,7 @@ impl HumanEmitter {
22662266 }
22672267
22682268 // 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 ;
22712270
22722271 // length of the code to be substituted
22732272 let snippet_len = span_end_pos as isize - span_start_pos as isize ;
@@ -2282,7 +2281,7 @@ impl HumanEmitter {
22822281 // if we elided some lines, add an ellipsis
22832282 if lines. next ( ) . is_some ( ) {
22842283 let placeholder = self . margin ( ) ;
2285- let padding: usize = placeholder . chars ( ) . map ( |ch| char_width ( ch ) ) . sum ( ) ;
2284+ let padding = str_width ( placeholder ) ;
22862285 buffer. puts (
22872286 row_num,
22882287 max_line_num_len. saturating_sub ( padding) ,
0 commit comments