@@ -2175,30 +2175,69 @@ impl EmitterWriter {
21752175 file_lines : & FileLines ,
21762176 is_multiline : bool ,
21772177 ) {
2178- // Print the span column to avoid confusion
2179- buffer. puts ( * row_num, 0 , & self . maybe_anonymized ( line_start + line_pos) , Style :: LineNumber ) ;
21802178 if let DisplaySuggestion :: Diff = show_code_change {
21812179 // Add the line number for both addition and removal to drive the point home.
21822180 //
21832181 // N - fn foo<A: T>(bar: A) {
21842182 // N + fn foo(bar: impl T) {
2183+ let number_of_lines = file_lines. lines . len ( ) ;
2184+ for ( index, line_to_remove) in
2185+ file_lines. lines . iter ( ) . take ( number_of_lines - 1 ) . enumerate ( )
2186+ {
2187+ buffer. puts (
2188+ * row_num - 1 ,
2189+ 0 ,
2190+ & self . maybe_anonymized ( line_start + line_pos + index) ,
2191+ Style :: LineNumber ,
2192+ ) ;
2193+ buffer. puts ( * row_num - 1 , max_line_num_len + 1 , "- " , Style :: Removal ) ;
2194+ buffer. puts (
2195+ * row_num - 1 ,
2196+ max_line_num_len + 3 ,
2197+ & normalize_whitespace (
2198+ & file_lines. file . get_line ( line_to_remove. line_index ) . unwrap ( ) ,
2199+ ) ,
2200+ Style :: NoStyle ,
2201+ ) ;
2202+ * row_num += 1 ;
2203+ }
2204+ let last_line = & file_lines
2205+ . file
2206+ . get_line ( file_lines. lines [ number_of_lines - 1 ] . line_index )
2207+ . unwrap ( ) ;
2208+ if last_line != line {
2209+ buffer. puts (
2210+ * row_num - 1 ,
2211+ 0 ,
2212+ & self . maybe_anonymized ( line_start + line_pos + number_of_lines - 1 ) ,
2213+ Style :: LineNumber ,
2214+ ) ;
2215+ buffer. puts ( * row_num - 1 , max_line_num_len + 1 , "- " , Style :: Removal ) ;
2216+ buffer. puts (
2217+ * row_num - 1 ,
2218+ max_line_num_len + 3 ,
2219+ & normalize_whitespace ( last_line) ,
2220+ Style :: NoStyle ,
2221+ ) ;
2222+ buffer. puts (
2223+ * row_num,
2224+ 0 ,
2225+ & self . maybe_anonymized ( line_start + line_pos) ,
2226+ Style :: LineNumber ,
2227+ ) ;
2228+ buffer. puts ( * row_num, max_line_num_len + 1 , "+ " , Style :: Addition ) ;
2229+ // print the suggestion
2230+ buffer. append ( * row_num, & normalize_whitespace ( line) , Style :: NoStyle ) ;
2231+ } else {
2232+ * row_num -= 2 ;
2233+ }
2234+ } else if is_multiline {
21852235 buffer. puts (
2186- * row_num - 1 ,
2236+ * row_num,
21872237 0 ,
21882238 & self . maybe_anonymized ( line_start + line_pos) ,
21892239 Style :: LineNumber ,
21902240 ) ;
2191- buffer. puts ( * row_num - 1 , max_line_num_len + 1 , "- " , Style :: Removal ) ;
2192- buffer. puts (
2193- * row_num - 1 ,
2194- max_line_num_len + 3 ,
2195- & normalize_whitespace (
2196- & file_lines. file . get_line ( file_lines. lines [ line_pos] . line_index ) . unwrap ( ) ,
2197- ) ,
2198- Style :: NoStyle ,
2199- ) ;
2200- buffer. puts ( * row_num, max_line_num_len + 1 , "+ " , Style :: Addition ) ;
2201- } else if is_multiline {
22022241 match & highlight_parts[ ..] {
22032242 [ SubstitutionHighlight { start : 0 , end } ] if * end == line. len ( ) => {
22042243 buffer. puts ( * row_num, max_line_num_len + 1 , "+ " , Style :: Addition ) ;
@@ -2210,13 +2249,20 @@ impl EmitterWriter {
22102249 buffer. puts ( * row_num, max_line_num_len + 1 , "~ " , Style :: Addition ) ;
22112250 }
22122251 }
2252+ // print the suggestion
2253+ buffer. append ( * row_num, & normalize_whitespace ( line) , Style :: NoStyle ) ;
22132254 } else {
2255+ buffer. puts (
2256+ * row_num,
2257+ 0 ,
2258+ & self . maybe_anonymized ( line_start + line_pos) ,
2259+ Style :: LineNumber ,
2260+ ) ;
22142261 draw_col_separator ( buffer, * row_num, max_line_num_len + 1 ) ;
2262+ // print the suggestion
2263+ buffer. append ( * row_num, & normalize_whitespace ( line) , Style :: NoStyle ) ;
22152264 }
22162265
2217- // print the suggestion
2218- buffer. append ( * row_num, & normalize_whitespace ( line) , Style :: NoStyle ) ;
2219-
22202266 // Colorize addition/replacements with green.
22212267 for & SubstitutionHighlight { start, end } in highlight_parts {
22222268 // Account for tabs when highlighting (#87972).
0 commit comments